TimeDelay

By | 2002-06-01

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.

Original Author: Mitch Mooney

Inputs

Delay as Long, milliseconds

Assumptions

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)

Returns

TimeDelay as boolean, turns turn if time reached,else false

API Declarations

Declare Function GetTickCount& Lib “kernel32” ()

Code



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

Author: dwirch

Derek Wirch is a seasoned IT professional with an impressive career dating back to 1986. He brings a wealth of knowledge and hands-on experience that is invaluable to those embarking on their journey in the tech industry.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.