PDA

Click to See Complete Forum and Search --> : Help... Question about Stopwatch program...


Wen Lie
Nov 12th, 1999, 11:12 AM
Dear All..

I need help in order to make a stopwatch program...
I confuse about the time set... Could anyone help me ???

Thx...

Wille
Junior VB Programmer

Bob Baddeley
Nov 12th, 1999, 11:14 AM
heehee. I mean use a watch like you wear on your wrist to time it. It would be easier than writing the program. :)

Wen Lie
Nov 12th, 1999, 11:21 AM
Sorry...
But, what do u mean by that Bob ???

Could u explain it to me ???

thx..

Wille

Aaron Young
Nov 12th, 1999, 11:24 AM
Try:

In a Form with a CommandButton and a Timer Control..

Private Sub Command1_Click()
Timer1.Tag = "X"
Timer1.Enabled = (Command1.Caption = "Start")
Command1.Caption = IIf(Command1.Caption = "Start", "Stop", "Start")
End Sub

Private Sub Form_Load()
Command1.Default = True
Command1.Caption = "Start"
Timer1.Enabled = False
Timer1.Interval = 10
End Sub

Private Sub Timer1_Timer()
Static tTimer As Single
If Len(Timer1.Tag) Then
tTimer = Timer
Timer1.Tag = ""
End If
Caption = Format((Timer - tTimer), "Standard")
End Sub



------------------
Aaron Young
Analyst Programmer
aarony@redwingsoftware.com
adyoung@win.bright.net

Wen Lie
Nov 12th, 1999, 12:23 PM
Thx Mr. Aaron...

I've tried your code, and it works...
but... I want to ask again... How can I set the time into zero again (when the time has reach 60 seconds) ???
and if I want to format the output into hh:mm:ss, how can I do it ???

Thx.....

Wille

Aaron Young
Nov 12th, 1999, 01:23 PM
Modify the Timer Event in the Following Way:

Private Sub Timer1_Timer()
Static tTimer As Single
Dim tSecs As Single
If Len(Timer1.Tag) Then
tTimer = Timer
Timer1.Tag = ""
End If
tSecs = Timer - tTimer
Caption = Format(TimeSerial(0, 0, tSecs), "HH:MM:SS") & "." & Format((tSecs - Int(tSecs)) * 100, "00")
End Sub

N.B. This will only count to ~9hrs as the TimeSerial Function Requires an Integer

------------------
Aaron Young
Analyst Programmer
aarony@redwingsoftware.com
adyoung@win.bright.net