Article ID: 180736
Article Last Modified on 6/29/2004
Option Explicit
Declare Function SetTimer Lib "user32" _
(ByVal hwnd As Long, _
ByVal nIDEvent As Long, _
ByVal uElapse As Long, _
ByVal lpTimerFunc As Long) As Long
Declare Function KillTimer Lib "user32" _
(ByVal hwnd As Long, _
ByVal nIDEvent As Long) As Long
Global iCounter As Integer
Sub TimerProc(ByVal hwnd As Long, _
ByVal uMsg As Long, _
ByVal idEvent As Long, _
ByVal dwTime As Long)
iCounter = iCounter + 1
Form1.Text1.Text = CStr(iCounter)
End Sub
Option Explicit
Dim lngTimerID As Long
Dim BlnTimer As Boolean
Private Sub Form_Load()
BlnTimer = False
Command1.Caption = "Start Timer"
End Sub
Private Sub Command1_Click()
'Starts and stops the timer.
If BlnTimer = False Then
lngTimerID = SetTimer(0, 0, 200, AddressOf TimerProc)
If lngTimerID = 0 Then
MsgBox "Timer not created. Ending Program"
Exit Sub
End If
BlnTimer = True
Command1.Caption = "Stop Timer"
Else
lngTimerID = KillTimer(0, lngTimerID)
If lngTimerID = 0 Then
MsgBox "couldn't kill the timer"
End If
BlnTimer = False
Command1.Caption = "Start Timer"
End If
End Sub
Keywords: kbhowto kbapi kbcontrol KB180736