VBABeginer_Chappers
New Member
- Joined
- Mar 8, 2018
- Messages
- 10
Thank you in advance for any help.
I have been trying to create a play sheet for a game using active X controls. I'm stuck at the moment with my timer. I have 3 command buttons and a text box. The text box displays the timer, the buttons are as follows Start Game, Pause Game & Reset Timer.
My code works for starting the timer, pausing the timer and resetting the timer, however when I press the pause button for the second time to recommence the timer I get a type mismatch error.
Please can someone tell me what is wrong with my code?
Thank you.
Chappers
I have been trying to create a play sheet for a game using active X controls. I'm stuck at the moment with my timer. I have 3 command buttons and a text box. The text box displays the timer, the buttons are as follows Start Game, Pause Game & Reset Timer.
My code works for starting the timer, pausing the timer and resetting the timer, however when I press the pause button for the second time to recommence the timer I get a type mismatch error.
Please can someone tell me what is wrong with my code?
Code:
Dim GameNo As String
Dim Start, RunTime, ElapsedTime
Dim PauseStart, PauseRunTime, PauseElapsedTime, PauseEnd
-----------------------------------------------------------------------------
Sub StartTimer()
Sheets("Sheet2").Range("L31").Value = 0
PauseElapsedTime = "0"
PauseRunTime = "0"
Start = Timer
Debug.Print Start
Call Timer_Loop
Sheets("Sheet2").TimerBox.Value = ElapsedTime
Application.StatusBar = False
End Sub
---------------------------------------------------------------------------
Sub PauseTimer()
If Sheets("Sheet2").Range("L32").Value = 1 Then
Sheets("Sheet2").Range("L31").Value = 1
Sheets("Sheet2").Range("L32").Value = 0
Sheets("Sheet2").Range("L33").Value = Sheets("Sheet2").TimerBox.Value
PauseStart = Timer
Else
Sheets("Sheet2").Range("L31").Value = 0
Sheets("Sheet2").Range("L32").Value = 1
PauseEnd = Timer
PauseRunTime = Format(((PauseEnd - PauseStart) + PauseRunTime) / 86400, "hh:mm:ss")
Sheets("Sheet2").Range("L34").Value = PauseRunTime
Call Timer_Loop
End If
End Sub
-------------------------------------------------------------------------
Sub ResetTimer()
Sheets("Sheet2").Range("L31").Value = "2"
Sheets("Sheet2").TimerBox.Value = Format(0, "hh:mm:ss")
Sheets("Sheet2").Range("L32").Value = "1"
End Sub
-----------------------------------------------------------------------------
Sub Timer_Loop()
Do While Sheets("Sheet2").Range("L31").Value = 0
DoEvents
RunTime = Timer
ElapsedTime = Format((RunTime - (Start + PauseRunTime)) / 86400, "hh:mm:ss")
Sheets("Sheet2").TimerBox.Value = ElapsedTime
Application.StatusBar = ElapsedTime
Loop
End Sub
Thank you.
Chappers