n-generation
asked on
Producing a Stop watch.
I want to produce a stopwatch, (i.e. a timer) able to display minutes, seconds, miliseconds. How will I get round doing this?
Thanks.
Thanks.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Put the following declaration in a module:
Public Declare Function GetTickCount Lib "kernel32" () As Long
On your form, place a timer control (Timer1) with an interval of 1 (ie, 1 millisecond), and a label (Label1).
Private Sub Timer1_Timer()
Static lngStart As Long
Dim ms As Long
Dim h As Long
Dim m As Long
Dim s As Long
If lngStart = 0 Then
lngStart = GetTickCount() 'first time
End If
'milliseconds since start
ms = GetTickCount() - lngStart
'break milliseconds into parts
s = Int(ms / 1000)
ms = ms - (s * 1000)
m = Int(s / 60)
s = s - (m * 60)
h = Int(m / 60)
m = m - (h * 60)
'show current elapsed time
Label1.Caption = Format(h) & ":" & Format(m, "00") & ":" & Format(s, "00") & "." & Format(ms, "000")
End Sub
Public Declare Function GetTickCount Lib "kernel32" () As Long
On your form, place a timer control (Timer1) with an interval of 1 (ie, 1 millisecond), and a label (Label1).
Private Sub Timer1_Timer()
Static lngStart As Long
Dim ms As Long
Dim h As Long
Dim m As Long
Dim s As Long
If lngStart = 0 Then
lngStart = GetTickCount() 'first time
End If
'milliseconds since start
ms = GetTickCount() - lngStart
'break milliseconds into parts
s = Int(ms / 1000)
ms = ms - (s * 1000)
m = Int(s / 60)
s = s - (m * 60)
h = Int(m / 60)
m = m - (h * 60)
'show current elapsed time
Label1.Caption = Format(h) & ":" & Format(m, "00") & ":" & Format(s, "00") & "." & Format(ms, "000")
End Sub
http://www.mvps.org/ccrp/
There is a hi-performance timer control.