VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Code-Based Timers

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

Start and kill a timer using API calls only! Useful when you need timers that can't be placed on a form.

Assumes
The routine that will be called every Timer milliseconds, MUST be placed in a standard module! It can't be placed on a form, or in a class.
API Declarations
Private Declare Function SetTimer Lib "user32" (ByVal hWnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Private Declare Function KillTimer Lib "user32" (ByVal hWnd As Long, ByVal nIDEvent As Long) As Long

Rate Code-Based Timers

'Make this a global variable, or site it
'in the same module as MainLoop.
Public Timer as Long
'To set the timer, issue the 
'following, where MainLoop 
'is the name of the procedure 
'to call every 500 milliseconds.
'Note that MainLoop MUST exist 
'in a BAS module!
Timer = SetTimer(0, 0, 500, AddressOf MainLoop)
'To kill the timer, 
'issue the following:
KillTimer 0, Timer

Download this snippet    Add to My Saved Code

Code-Based Timers Comments

No comments have been posted about Code-Based Timers. Why not be the first to post a comment about Code-Based Timers.

Post your comment

Subject:
Message:
0/1000 characters