For both of these examples, you need a label (called lblMsg) and a timer called tmrEvent.
Count Down Example
This example counts down from 10 when the form is loaded.
Private lngCountDownValue As Long '// variable that stores countdown
value
Private Sub Form_Load()
lngCountDownValue = 10 '// count down from 10
tmrEvent.Interval = 1000 '// 1 second
'// call the timer now for the first interval
'// (otherwise we would have to wait 1 second)
Call tmrEvent_Timer
tmrEvent.Enabled = True '// timer is enabled
End Sub
Private Sub tmrEvent_Timer()
lngCountDownValue = lngCountDownValue - 1 '// decrement the
value
lblMsg.Caption = lngCountDownValue & " seconds remaining"
If lngCountDownValue = 0 Then
'// time expired
'// do not allow this procedure
to call again.
tmrEvent.Enabled = False
Msgbox "Time has expired"
End If
End Sub
Clock Example
This example displays a clock.
Private Sub Form_Load()
tmrEvent.Interval = 1000 '// 1 second
'// call the timer now for the first interval
'// (otherwise we would have to wait 1 second)
Call tmrEvent_Timer
tmrEvent.Enabled = True '// timer is enabled
End Sub
Private Sub tmrEvent_Timer()
'// update the time
lblMsg.Caption = "Time: " & Time()
End Sub
Comments