CodeItBetter Programming Another VB Programming Blog

How to use Timer without using timer control

Posted on January 4, 2009
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
'Controls - How to use Timer without using timer control
' 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
Private mlngTimerID As Long
 
' Module code
Public Sub StartTimer(lngInterval As Long)
    mlngTimerID = SetTimer(0, 0, lngInterval, AddressOf TimerCallBack)
End Sub
 
Public Sub TimerCallBack(ByVal hwnd As Long, ByVal uMsg As Long, ByVal idEvent As Long, _
    ByVal dwTime As Long)
    'Do Something Here
Range("A1").Value = Format$(Now, "HH:mm:ss")
End Sub
 
Public Sub StopTimer()
    KillTimer 0, mlngTimerID
End Sub
 
'How can I call this function:
'Call StartTimer(1000)'To start the timer [1000 = 1 second]
'call StopTimer'To stop the timer
Filed under: Controls Leave a comment
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


 

No trackbacks yet.