How to Stop a Big Loop
Visual Basic
2
Posts
2
Posters
0
Views
1
Watching
-
:confused: Hi everyone ... When i am inside a big loop in VB6 (for .. to; if .. then; while .. wend) the form stops responding. How can I make a stop button in the form ?? Thank you ;), Rodrigo
You need to provide a means to break the loop. This is an example (untested), but you should get the idea:
dim StopButtonPressed as Boolean sub MyLongLoopSubroutine() StopButtonPressed = false while (MyCondition = true ) and (StopButtonPressed = false) ' do loop stuff here ' DoEvents allows the UI and other windows messages to get through DoEvents wend end sub sub StopButton_Click() StopButtonPressed = true end sub
Bear in mind you need to be careful when using DoEvents to keep a user interface responsive, as any actions the user has may interfere with the loop you're running. -- Ian Darling "The moral of the story is that with a contrived example, you can prove anything." - Joel Spolsky