Hi -
So I'm trying to get a stopwatch on a userform that has a bunch of other fields as well.
This is the code that I'm using:
Dim StopTimer As Boolean
Dim Etime As Single
Dim Etime0 As Single
Dim LastEtime As Single
End Sub
Private Sub TimeReset_Click()
StopTimer = True
Etime = 0
Etime0 = 0
LastEtime = 0
TimeBox.Value = "00:00:00.00"
End Sub
Private Sub TimeStart_Click()
StopTimer = False
Etime0 = Timer() - LastEtime
Do Until StopTimer
Etime = Int((Timer() - Etime0) * 100) / 100
If Etime > LastEtime Then
LastEtime = Etime
TimeBox.Value = Format(Etime / 86400, "hh:mm:ss.") & Format(Etime * 100 Mod 100, "00")
DoEvents
End If
Loop
End Sub
Private Sub TimeStop_Click()
StopTimer = True
Beep
End Sub
Right now, the stop watch begins counting, but the stop and reset buttons do not work. When I hit submit on the form, it copies the time to another worksheet (as it should) but there is no way to stop the clock unless I hit submit.
I have the first four lines in the Initialize section of the Userform.
Thanks for your help!
So I'm trying to get a stopwatch on a userform that has a bunch of other fields as well.
This is the code that I'm using:
Dim StopTimer As Boolean
Dim Etime As Single
Dim Etime0 As Single
Dim LastEtime As Single
End Sub
Private Sub TimeReset_Click()
StopTimer = True
Etime = 0
Etime0 = 0
LastEtime = 0
TimeBox.Value = "00:00:00.00"
End Sub
Private Sub TimeStart_Click()
StopTimer = False
Etime0 = Timer() - LastEtime
Do Until StopTimer
Etime = Int((Timer() - Etime0) * 100) / 100
If Etime > LastEtime Then
LastEtime = Etime
TimeBox.Value = Format(Etime / 86400, "hh:mm:ss.") & Format(Etime * 100 Mod 100, "00")
DoEvents
End If
Loop
End Sub
Private Sub TimeStop_Click()
StopTimer = True
Beep
End Sub
Right now, the stop watch begins counting, but the stop and reset buttons do not work. When I hit submit on the form, it copies the time to another worksheet (as it should) but there is no way to stop the clock unless I hit submit.
I have the first four lines in the Initialize section of the Userform.
Thanks for your help!