Link to home
Start Free TrialLog in
Avatar of BubbaisBest
BubbaisBest

asked on

Need to halt execution of code for brief timeframe

I am new to VB and my code is executing so fast that it is processing some files before the previous file finished processing.  Is there a command that will halt execution for a very short timeframe say .5 to 1 second before it continues?  I have been looking at Sleep but don't know if that is best or if there are other commands that are more useful.

Thanks in advance,
Bubs
ASKER CERTIFIED SOLUTION
Avatar of codeconqueror
codeconqueror

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of codeconqueror
codeconqueror

Either will do the job.  But, if you time it out just right so that the 1/2 of a second lands at exactly 12:00:00 AM midnight, it might cause a problem so you can do something like this:

Dim sngTimer As Single
Dim sngStartTimer As Single
sngTimer = Timer + 0.5 '**** Add 1/2 second (500 ms) to the current time
sngStartTimer = Timer '**** Store the current value of Timer
Do While Timer < sngTimer '**** Loop while the value of Timer is less than the start time plus 500 ms
     If Timer < sngStartTimer Then '**** If we hit midnight and timer is now less than it's starting value, exit the loop
           Exit Do '**** Exit the loop
     End If
     DoEvents '**** DoEvents so we don't look like the program isn't responding
Loop
Avatar of BubbaisBest

ASKER

Thank you for all your help codeconqueror.

I just used the Sleep methodology and it comes out fine now at .5 seconds.

Bubs
No prob. :)