Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Create a clock to count 15 minutes

Status
Not open for further replies.

wvdw

Programmer
Jul 31, 2000
20
NL
Hi,

What I want to do is make a timer that keeps track of the time of a sportsmatch. So the textbox or whatever has to start at zero (00:00) and count every second that the game is progressing. How do I add second to a textbox or any other field on a form?

Thanks for your help.

 
You could use a timer control, and set its Interval to 1000 (milliseconds).
 
Mike,

Thank you for the tip but I did know that part of the puzzle. I have a timer and what do I do on the timer event. Do I make a text box with a value of 0.0 and format it as mm:ss (then I get 12:00 and I want 00:00) and how do I add the new second to the value in the textbox (whatever format or value that has)?

I hope you have the anwer.
 
'set tmrMain.Interval to 100 for this code:
'this has milliseconds:

Private Sub cmdStart_Click()
tmrMain.Enabled = True
End Sub

Private Sub cmdStop_Click()
tmrMain.Enabled = False
End Sub

Private Sub tmrMain_Timer()
Static MilliSeconds As Integer
Static Seconds As Integer
Static Minutes As Integer
Static Hours As Integer

MilliSeconds = MilliSeconds + 1

If MilliSeconds = 10 Then
Seconds = Seconds + 1
MilliSeconds = 0
End If

If Seconds = 60 Then
Minutes = Minutes + 1
Seconds = 0
End If

If Minutes = 60 Then
Hours = Hours + 1
Minutes = 0
End If

If Hours >= 12 Then
MsgBox "This timer isn't good for more than 12 hours, please add your own code here!", vbInformation
End If

txtElapsedTime.Text = Hours & " : " & Minutes & " : " & Seconds & " . " & MilliSeconds

End Sub

Good luck!

-Mike
Difference between a madman and a genius:
A madman uses his genius destructively,
A genius uses his madness constructively.
 
Here's an example of one way to do it:


Option Explicit
Private ClockStart As Date

Private Sub Command1_Click()
ClockStart = Now()
Timer1.Enabled = Not Timer1.Enabled
End Sub

Private Sub Timer1_Timer()
Text1.Text = Format(Now() - ClockStart, "Nn:Ss")
End Sub
 
I guess I should have mentioned that the interval on the timer should be set to 1000 for the above example
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top