VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Timeout/Pause

by Xeek (2 Submissions)
Category: Miscellaneous
Compatability: Visual Basic 3.0
Difficulty: Intermediate
Date Added: Wed 3rd February 2021
Rating: (2 Votes)

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

Inputs
Duration - Specify the seconds you want to pause execution for
Assumes
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

Rate Timeout/Pause

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

Download this snippet    Add to My Saved Code

Timeout/Pause Comments

No comments have been posted about Timeout/Pause. Why not be the first to post a comment about Timeout/Pause.

Post your comment

Subject:
Message:
0/1000 characters