Click to See Complete Forum and Search --> : timer question


Felicity
May 20th, 2001, 02:37 AM
I am trying to creat a stop watch using three labels and three timers (minutes, seconds and tenths of a second). So far I have the tenths of a second working with this:
lblTSec.Caption = lblTSec.Caption + 1
how do I make it start at zero again once it reaches 59 and what speed do I set the timers at for minutes and seconds?

slcotten
May 20th, 2001, 07:25 AM
The Interval property of a timer is measured in miliseconds... therefore a tenth of a second is 10... a second is 1000 and one minute is 60000.

To reset the lbl to 0 do this:


If CInt(lblTSec.Caption) = 59 then
lblTSec.Caption = "0"
end if





You can do it with one timer like this:



private Sub tmrClock_Timer()
Dim nSec as Integer
Dim nTSec as Integer
Dim nMin as Integer

nTSec = CInt(lblTSec.Caption)
nSec = CInt(lblSec.Caption)
nMin = CInt(lblMin.Caption)

nTSec = nTSec + 1

If nTSec = 100 then
nTSec = 0
nSec = nSec + 1
End If

If nSec = 60 then
nSec = 0
nMin = nMin + 1
End If

lblTSec.Caption = CStr(nTSec)
lblSec.Caption = CStr(nSec)
lblMin.Caption = CStr(nMin)
End Sub





Hope this helps.