There are a few ways to do what you're referring to. Perhaps the most reliable method is to save the time you started the countdown in a variable, then calculate the values for the clock display in your code. I made a small example project to help illustrate my answer. I included a Label, a Timer, and two Command Buttons. I didn't name any of them, but the Label displays the current countdown time. The way I set this up, you start the countdown from 20:00.0 using Command1 (the Start/Stop button). You can pause the countdown using Command2 (Pause/Resume). If you stop the countdown by pressing Command1 again, it will reset the timer to 20:00.0. If you pause the countdown (Command2) and then use the Start/Stop button (Command1), it will actually restart the countdown from 20:00.0, which may not be what you expected. Here's the code for what I did:
Private CountDownStart
Private Sub Command1_Click()
If Not Timer1.Enabled Then
CountDownStart = Timer
Timer1.Enabled = True
Command1.Caption = "Stop"
Command2.Caption = "Pause"
Command2.Enabled = True
Else
Timer1.Enabled = False
MsgBox "Final Time: " & Label1.Caption & vbCrLf & vbCrLf & "Click OK to reset the clock."
Label1 = "20:00.0"
Command1.Caption = "Start"
Command2.Caption = "-----"
Command2.Enabled = False
End If
End Sub
Private Sub Command2_Click()
Static PauseInterval
If Timer1.Enabled Then
PauseInterval = Timer - CountDownStart
Timer1.Enabled = False
Command1.Caption = "Restart"
Command2.Caption = "Resume"
Else
CountDownStart = Timer - PauseInterval
Timer1.Enabled = True
Command1.Caption = "Stop"
Command2.Caption = "Pause"
End If
End Sub
Private Sub Timer1_Timer()
TimeDiff = (12000) - Int((Timer - CountDownStart) * 10)
If TimeDiff >= 0 Then
TenthDiff = TimeDiff Mod 10
SecDiff = Int(TimeDiff / 10) Mod 60
MinDiff = Int(TimeDiff / 600)
Label1 = Format(MinDiff, "00") & ":" & Format(SecDiff, "00") & "." & Format(TenthDiff, "0")
Else
Label1 = "00:00.0"
Timer1.Enabled = False
MsgBox "!!!TIME!!!"
Command1.Caption = "Start"
Command2.Caption = "-----"
Command2.Enabled = False
End If
DoEvents
End Sub
Tweak that until it fits what you're trying to do with it. The code above is to just give you an idea about one way to do it - likely the most reliable way, as it depends on the system clock to tell it how much time is left rather than counting the number of times the Timer was set off.
Why is it unreliable to just count the number of times that the Timer is set off? Let's say that you are running the above code on a slower machine. Let's say that you want to start another program while the countdown is running - in keeping with your situation, let's say you're opening a Word document to look up the stats of a certain player. Doing this on a slower computer will throw off your timing because the system won't be able to set off the Timer exactly every 10th of a second. The Interval property of the Timer control is just a minimum value. No less than a tenth of a second will pass before the system sets off the Timer again. So imagine the Word document taking all of the processor's time for a full three minutes. You go back to your countdown, and it's three minutes behind!
By checking against the system clock, you can be assured that your timer won't be off, since the system clock doesn't require any software to keep track of the time. It's all done in hardware. That's why the way I did it above is more reliable.
If you have any more questions about this or anything else, feel free to ask. Go well, and may the Winds favor you in your journey.
- Sendoshin