Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I would appreciate help to create a simple VB application with one form with buttons 'Start' and 'Stop'. When Start is clicked, a loop shall start. When Stop is clicked, the loop shall stop. I know how to create a form, but how do I connect it to the code? For example, can I use something like:
Do Until <condition>
...
...
LoopHow then shall I code the condition?
Or maybe another approach would be better...

You first declare a variable to hold the condition in the General section of the form:
Dim Test as boolean
You then put the loop in the Start event:
Private Sub Start_Click()
Test = False
Do Until Test = True
...
...
Do Events
LoopEnd Sub
You will need a Do Events command within the loop otherwise the Stop command will never get actioned until the loop terminates.
Pressing Stop will then terminate the loop.
Private Sub Stop_Click()
Test = True
End Sub
However, creating an endless loop that requires an external even to terminate it is not good programming practice. It makes for DOS BASIC type spaghetti code which VB done properly eliminates.
Whatever it is you are trying to do, there is probably a better way of doing it, possibly a timed loop.
Stuart

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |