Computing.Net > Forums > Programming > Visual Basic 5 - simple loop...

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Visual Basic 5 - simple loop...

Reply to Message Icon

Name: legolas
Date: September 1, 2008 at 00:12:34 Pacific
OS: Win XP
CPU/Ram: 1.8 GHz AMD
Product: Acer
Comment:

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>
...
...
Loop

How then shall I code the condition?
Or maybe another approach would be better...



Sponsored Link
Ads by Google

Response Number 1
Name: StuartS
Date: September 1, 2008 at 05:30:01 Pacific
Reply:

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
Loop

End 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


0
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Visual Basic 5 - simple loop...

ftp transfer in visual basic 5 www.computing.net/answers/programming/ftp-transfer-in-visual-basic-5/16942.html

visual basic 5/6 installer www.computing.net/answers/programming/visual-basic-56-installer/9918.html

5 Visual Basic Programmers Needed www.computing.net/answers/programming/5-visual-basic-programmers-needed/3969.html