Search Tools Links Login


You can pause execution of code for the specified duration. Different from "Sleep" api in that it will not lock up the whole program.

Original Author: Xeek


Duration - Specify the seconds you want to pause execution for


GetTickCount(api), like Timer resets at some point. Timer resets at midnight, and returns the seconds since midnight. GetTickCount returns the ticks (milliseconds) since the o/s was started. I remember reading that it resets to 0 after 49.7 days (different o/s may vary [windows]). I don't think it should cause a problem, but it may result in the loop, looping indefinitely until the program is shut down. This is slightly more accurate than timeout/pause routines that use Timer.

API Declarations

Declare Function GetTickCount Lib "kernel32" Alias "GetTickCount" () As Long


Sub Pause(Duration As Double)
'example: Pause (0.8) 'pause for .8 seconds
Dim start As Double 'declare variable
  start# = GetTickCount 'store milliseconds since boot
  Do: DoEvents 'start loop
On Error Resume Next 'dunno, kept giving me an error once. so i put this here and it stopped giving me the error
  Loop Until GetTickCount - start# >= (Duration# * 1000) 'loop until the actual time (minus stored time) is greater than or equal to the duration (seconds * 1000 = milliseconds)
End Sub

About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 87 times


Visual Basic 6


No attachments for this post

Loading Comments ...


No comments have been added for this post.

You must be logged in to make a comment.