Hey Everyone!
So I am getting a bit stuck here - I have a timer that works (for the most part) the issue is when the userform is hidden and re-opened the "Continue" feature doesn't work anymore. Meaning the timer doesn't continue counting. Hope I can get some help please see my code below and a screen grab of the user form for reference. (Side note if I keep the UserForm open and click "continue" it works fine - hiding it somehow disrupts the code).
Option Explicit
Dim CmdStop As Boolean
Dim Paused As Boolean
Dim Start
Dim TimerValue As Date
Dim pausedTime As Date
Sub btnStart_Click()
btnPause.Enabled = True
CmdStop = False
Paused = False
Start = Now() ' Set start time.
btnPause.Enabled = True
btnStop.Enabled = True
btnReset.Enabled = False
Do While CmdStop = False
If Not Paused Then
TimerValue = Now() - Start - pausedTime
Else
pausedTime = Now() - TimerValue - Start
End If
TimerReadOut = Format(TimerValue, "h:mm:ss")
DoEvents ' Yield to other processes.
Loop
End Sub
Sub btnPause_Click()
btnStart.Enabled = False
If btnPause.Caption = "Pause" Then
Paused = True
btnPause.Caption = "Continue"
Else
Paused = False
btnPause.Caption = "Pause"
End If
End Sub
Sub BtnReset_Click()
TimerReadOut = "0:00:00"
btnStop.Enabled = False
Unload UserForm1
End Sub
Sub BtnStop_Click()
btnPause.Enabled = False
btnReset.Enabled = True
btnStop.Enabled = False
CmdStop = True
Sheet1.Range("M8").Value = TimerReadOut.Value
If TimerReadOut.Value = "" Then Sheet1.Range("M8").Value = ""
UserForm1.Hide
End Sub
Private Sub BtnReset_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
If Shift = 0 Then
Range("N8") = Range("N8") + 1
Else: Range("N8") = Range("N8") - 1
End If
End Sub
Private Sub UserForm1_Initialize()
TimerReadOut.Value = Sheet14.Range("C3").Value
Sheet14.Range("C3").Value = TimerReadOut.Value
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = vbFormControlMenu Then
Me.Hide
Cancel = True
End If
End Sub
So I am getting a bit stuck here - I have a timer that works (for the most part) the issue is when the userform is hidden and re-opened the "Continue" feature doesn't work anymore. Meaning the timer doesn't continue counting. Hope I can get some help please see my code below and a screen grab of the user form for reference. (Side note if I keep the UserForm open and click "continue" it works fine - hiding it somehow disrupts the code).
Option Explicit
Dim CmdStop As Boolean
Dim Paused As Boolean
Dim Start
Dim TimerValue As Date
Dim pausedTime As Date
Sub btnStart_Click()
btnPause.Enabled = True
CmdStop = False
Paused = False
Start = Now() ' Set start time.
btnPause.Enabled = True
btnStop.Enabled = True
btnReset.Enabled = False
Do While CmdStop = False
If Not Paused Then
TimerValue = Now() - Start - pausedTime
Else
pausedTime = Now() - TimerValue - Start
End If
TimerReadOut = Format(TimerValue, "h:mm:ss")
DoEvents ' Yield to other processes.
Loop
End Sub
Sub btnPause_Click()
btnStart.Enabled = False
If btnPause.Caption = "Pause" Then
Paused = True
btnPause.Caption = "Continue"
Else
Paused = False
btnPause.Caption = "Pause"
End If
End Sub
Sub BtnReset_Click()
TimerReadOut = "0:00:00"
btnStop.Enabled = False
Unload UserForm1
End Sub
Sub BtnStop_Click()
btnPause.Enabled = False
btnReset.Enabled = True
btnStop.Enabled = False
CmdStop = True
Sheet1.Range("M8").Value = TimerReadOut.Value
If TimerReadOut.Value = "" Then Sheet1.Range("M8").Value = ""
UserForm1.Hide
End Sub
Private Sub BtnReset_MouseUp(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
If Shift = 0 Then
Range("N8") = Range("N8") + 1
Else: Range("N8") = Range("N8") - 1
End If
End Sub
Private Sub UserForm1_Initialize()
TimerReadOut.Value = Sheet14.Range("C3").Value
Sheet14.Range("C3").Value = TimerReadOut.Value
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
If CloseMode = vbFormControlMenu Then
Me.Hide
Cancel = True
End If
End Sub