VB and VBA Users Source Code: Create a timer using API calls
[
Home
|
Contents
|
Search
|
Reply
| Previous | Next ]
VB/VBA Source Code
Create a timer using API calls
By:
Andrew Baker
Email (spam proof):
Email the originator of this post
Date:
Sunday, October 15, 2000
Hits:
6977
Category:
Windows API
Article:
The following code can be used instead of a the VB timer control, to create a routine which is continuous called at a specified time interval: Option Explicit 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 Private lTimerId As Long 'Purpose : Stops the timer routine 'Inputs : N/A 'Outputs : Returns True if the timer routine was stopped 'Author : Andrew Baker 'Date : 15/10/2000 15:24 'Notes : 'Revisions : Function EndTimer() As Boolean If lTimerId Then lTimerId = KillTimer(0&, lTimerId) lTimerId = 0 EndTimer = True End If End Function 'Purpose : Starts the continuous calling of a private routine at a specific time interval. 'Inputs : lInterval The interval (in ms) at which to call the routine 'Outputs : N/A 'Author : Andrew Baker 'Date : 15/10/2000 15:30 'Notes : 'Revisions : Sub StartTimer(lInterval As Long) If lTimerId Then 'End Current Timer EndTimer End If lTimerId = SetTimer(0&, 0&, ByVal lInterval, AddressOf TimerRoutine) End Sub 'Purpose : Routine which is called repeatedly by the timer API. 'Inputs : Inputs are automatically generated. 'Outputs : 'Author : Andrew Baker 'Date : 15/10/2000 15:32 'Notes : 'Revisions : Private Sub TimerRoutine(ByVal lHwnd As Long, ByVal lMsg As Long, ByVal lIDEvent As Long, ByVal lTime As Long) 'Place your code here... End Sub
Terms and Conditions
Support this site
Download a trial version of the Excel Workbook Rebuilder