Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pause in vb?

Status
Not open for further replies.

schembri

Programmer
Aug 29, 2003
8
MT
is there any function to make a program stop or wait for an ammount of time for example 1second before it continues to execute.

for example having a loop and want to delay it by one second each time it loops.
 

Do a search in this forum using the KeyWord "Sleep", or use a time comparison inside the loop.

Why do you need this? Usually something like this can be avoided.
 
i'm making a 384 channel light controller , controlled through the parallel port. And my ic's don't support the speed the bits are fed. so i need a small pause every time i have an out put.
 
Dim x
For x = 1 to 10000
DoEvents
next x

Just adjust the 10000 to your needs.
The DoEvents enables you to terminate the program during the loop.
 
I would go with calling the Sleep() API within that loop, perhaps with a delay value like 100 ms and then loop with Sleep() and DoEvents about 9 or 10 times.

This will leave your PC more responsive for other activities while your light controller program runs, and your program will be able to respond to "Cancel" button events as well. Have any cancel event handler set a module-global Boolean and be sure to test for this becoming True within your loop and take appropriate action.

This is a common type of thing, people use it for open-loop control of external devices such as EEPROM programmers all the time. I agree with CCLINT that a search here or on Google will get you to info on Sleep() pretty easily.

What sort of stinks is that DoEvents actually already calls Sleep() now, but it passes 0 as the time interval for "sleeping." Ah, if only they had provided the option of an interval parameter to DoEvents! But I suspect they were worried VB programmers would get themselves into trouble. A lot of VB is about providing padded, rounded surfaces so baby won't bump his head. I'd love to see a VB 6.1 that didn't make you ride in the child seat by default.

You just need to be like Tommy in Rug Rats, and use your screwdriver to pry the lock on the playpen open. Turns out it isn't all that hard.

This link describes Word VBA, but it applies as-is to VB6 as well:

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top