VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



TimeDelay

by Mitch Mooney (1 Submission)
Category: Miscellaneous
Compatability: Visual Basic 3.0
Difficulty: Unknown Difficulty
Date Added: Wed 3rd February 2021
Rating: (38 Votes)

TimeDelay fuction is good for when you want to time out a loop, in milliseconds.
Does'nt use a timer control, Uses simple api declare.

Inputs
Delay as Long, milliseconds
Assumes
Create a module with the following api declare and function Usage can be Do FuncThatRetunsTrue MoreCode EctEct Loop until ( FuncThatRetunsTrue=True) or (TimeDelay(60000)=True)
Code Returns
TimeDelay as boolean, turns turn if time reached,else false
API Declarations
Declare Function GetTickCount& Lib "kernel32" ()

Rate TimeDelay



Public Function TimeDelay(ByVal Delay As Long) As Boolean
Static Start As Long
Dim Elapsed As Long
If Start = 0 Then                            'if start is 0 then set a
  Start = GetTickCount                       'Static value to compare
End If
Elapsed = GetTickCount
If (Elapsed - Start) >= Delay Then
  TimeDelay = True
  Start = 0                            'Remember to reset start
Else: TimeDelay = False                 'once true so subsquent
End If                                'calls wont "spoof" on you!
End Function

Download this snippet    Add to My Saved Code

TimeDelay Comments

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

Post your comment

Subject:
Message:
0/1000 characters