Article ID: 176951
Article Last Modified on 7/13/2004
Event Notify(ByVal somenum As Double)
Public Sub StartTimer()
Call BeginTimer(Me) 'Start the timer
End Sub
Public Sub Notifyme(ByVal anum As Double)
RaiseEvent Notify(anum) 'Create an event with the result
End Sub 'as a parameter
Public Sub StopTimer()
Call EndTimer
End Sub
Private Sub Class_Terminate()
Call EndTimer 'Make sure the timer is stopped
End Sub
Global timerid As Long
Dim thetimer As clsTimer
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 EndTimer()
Dim retval As Long
retval = KillTimer(0, timerid)
End Sub
Public Sub BeginTimer(ByRef Timerobj As clsTimer)
Set thetimer = Timerobj
timerid = SetTimer(0, 0, 1, AddressOf TimerProc)
End Sub
Public Sub TimerProc(ByVal hwnd As Long, ByVal umsg As Long, _
ByVal idEvent As Long, ByVal dwtime As Long)
Dim counter As Long
Dim theanswer As Double
KillTimer 0, timerid 'Stop the timer
For counter = 1 To 15000000 'Do some work here
theanswer = theanswer + counter
Next counter
thetimer.Notifyme (theanswer) 'Work is done. Pass the result
End Sub 'as a parameter.
Public WithEvents obj As clsTimer
Private Sub Class_Terminate()
Set obj = Nothing
End Sub
Private Sub obj_Notify(ByVal somenum As Double)
Form1.lstTimes.AddItem somenum
obj.StopTimer
Set obj = Nothing 'Shut down the server when it has completed
End Sub 'the task.
Public Sub startit()
Set obj = New clsTimer
obj.StartTimer
End Sub
Dim notifyobject As clsNotify
Private Sub cmdStart_Click()
notifyobject.startit
End Sub
Private Sub Form_Load()
Set notifyobject = New clsNotify
End Sub
Additional query words: callback kbVBp500 kbVBp600 kbActiveX kbdse kbDSupport kbVBp
Keywords: kbhowto KB176951