Hello VBA gurus!
I'm currently using this code from another forum (http://www.mrexcel.com/forum/excel-q...tml#post171939) to make a stopwatch, but now I want to modify it a little to make it display how long I take to do things and if I pass a certain time period too much.
It's on a userform with 4 buttons: Start, Stop, Reset, and Exit.
I was wondering if it's possible to have it where when I press either Stop or Reset that it will store what ever time the stopwatch was at and display it on a label. Then if the stopwatch was above or below a certain time frame then it would display on a different label and have a running total until the user presses the Exit button.
Example:
Stopwatch is running. User presses Stop/Reset after 10 seconds have passed.
10 seconds would be displayed on label 1.
User starts stopwatch again, and presses Stop/Reset after 1 minute has passed.
1 minute would be displayed on label 2.
User starts stopwatch again, and presses Stop/Reset after 59 seconds have passed.
59 seconds would then be added to the 10 seconds on label 1.
User starts stopwatch again, and presses Stop/Reset after 1 minute and 59 seconds have passed.
1 minute and 59 seconds would then be added to the 1 minute on label 2.
(repeat)
What I know/tried so far:
I originally tried setting an "If/Then" procedure in the ResetBtn_click sub and made it read something along the lines of "If elapsedtimelbl.caption = "00:00:01.00" then label1.caption = elapsedtimelbl, but that didn't work, it only ended up showing me elapsedtimelbl instead of the stopped time.
So I came to the conclusion that I have to set it as a string and store it within memory somehow.
Note:
I can't download APIs since I use this only at work.
Thank you any help provided and thank you for taking the time to read this post,
lilhugo
Dim StopTimer As Boolean
Dim Etime As Single
Dim Etime0 As Single
Dim LastEtime As Single
Dim TimeAbove1Minute as String
Dim TimeBelow1Minute as String
Private Sub ExitBtn_Click()
Unload Me
End Sub
Private Sub ResetBtn_Click()
StopTimer = True
Etime = 0
Etime0 = 0
LastEtime = 0
ElapsedTimeLbl.Caption = "00:00:00.00"
End Sub
Private Sub StartBtn_Click()
StopTimer = False
Etime0 = Timer() - LastEtime
Do Until StopTimer
Etime = Int((Timer() - Etime0) * 100) / 100
If Etime > LastEtime Then
LastEtime = Etime
ElapsedTimeLbl.Caption = Format(Etime / 86400, "hh:mm:ss.") & Format(Etime * 100 Mod 100, "00")
DoEvents
End If
Loop
End Sub
Private Sub StopBtn_Click()
StopTimer = True
End Sub
Bookmarks