PDA

Click to See Complete Forum and Search --> : Stopping a Loop with a command button


sivad77
Nov 10th, 1999, 10:04 AM
I'm not experienced at all with VB but I'm using it on my Senior Design project and I'm kind of stumped. I just want to be able to start a loop with a start button and end it with a stop button. I'm fine with starting the loop - It's just that while the loop is executing, the cmdStop_Click() event cannot occur because the loop is executing. Can someone tell me a)if using a command button click event to stop a loop is possible and b)how would I go about it or where can I see an example of this in action?

Aaron Young
Nov 10th, 1999, 10:22 AM
Use DoEvents in your Loop to Enable the Other Events/Applications to Fire, then use a Module Level Variable to Flag when to Stop, eg.

Private bStop As Boolean

Private Sub Command1_Click()
bStop = True
End Sub

Private Sub Form_Activate()
Dim I As Long
While Not bStop
I = I + 1
Caption = "Looping.. " & I
DoEvents
Wend
Caption = "Loop Canceled"
End Sub



------------------
Aaron Young
Analyst Programmer
aarony@redwingsoftware.com
adyoung@win.bright.net