CodeItBetter Programming Another VB Programming Blog

How to allow timer function without 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
'System & API - How to allow timer function without timer control
'Allows a timer function without the need for the Visual basic "Timer" control.
'(Demonstrates callbacks and AddressOf)

Public Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, _
    ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Public Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
 
Public Sub VB_TIMERPROC(ByVal hwnd As Long, ByVal uint1 As Long, ByVal nEventId As Long, _
    ByVal dwParam As Long)
    On Error Resume Next
    'Timer click processing
    Form1.Label1.Caption = Format(Now, "hh:mm:ss")
End Sub
 
Private Sub Form_Load()
    Call SetTimer(Me.hwnd, 1, 1000, AddressOf VB_TIMERPROC)
End Sub
 
Private Sub Form_Unload(Cancel As Integer)
    Call KillTimer(Me.hwnd, 1)
End Sub
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


 

No trackbacks yet.