"...And the next sign of the Apocalypse will be..."
*****
On Tue, 20 Jan 2004 07:27:12 +1000, HP wrote:
Hi,
Does anyone know if it is possible to force the code to pause during every
iteration of a FOR ... NEXT loop, and wait for the user to click a command
button for the next iteration. I need to let the user step through the
looping at his/her own pace.
Any help would be greatly appreciated.
h.
If it was me, I'd have the button change a shared variable to indicate
that it's been clicked, and have your code check for that, like this:
Private wasClicked as Boolean
Sub myLoop()
For n = 1 To 9
Do Until wasClicked
DoEvents
Loop
wasClicked = False
'your code here
Next
End Sub
Sub Button1_Click()
wasClicked = True
End Sub
Alternately, you could write the code to run when the button was
clicked, and keep track of where it was using a static variable, like
this:
Sub Button1_Click()
Static x As Integer
x = x + 1 'replace 1 with the low end of your loop
If x <= 9 Then 'replace 9 with the high end of your loop
'your code here
End If
End Sub
....but then you'd have to figure out how to reinitialize the "loop" if
you ran it more than once.