A long time ago JoeMo posted code for userform countdown timer which works very well. But a question was asked about including code for pause and resume command buttons. My question is : has anyone looked into
including those buttons? Here is the code :
Public AllowedTime As Variant
Sub Open_count ()
AllowedTime = InputBox("Enter the time interval to countdown")
If AllowedTime = "" Then Exit Sub
UserForm2.Show
End Sub
Private Sub UserForm_Initialize()
Dim M As Double, S As Double
M = Int(CDbl(AllowedTime))
S = (CDbl(AllowedTime) - Int(CDbl(AllowedTime))) * 60
With tBx1
.Value = Format(CStr(M), "00") & ":" & Format(CStr(S), "00")
End With
End Sub
I dont have that second command butto i my userform
Private Sub CommandButton1_Click()
Dim t, E, M As Double, S As Double
'AllowedTime is set in sub 'modTestUserForm' for this user form
t = Timer
Do
'next If-End If protects in case clock was started just before midnight and Timer resets during countdown
If Timer - t < 0 Then
Unload UserForm1
MsgBox "Error encountered - start again"
Exit Sub
End If
E = CDbl(Time) * 24 * 60 * 60 - t 'elapsed time in secs
M = CDbl(AllowedTime) - 1 - Int(E / 60)
S = 59 - Round((E / 60 - Int(E / 60)) * 60, 0)
With tBx1
.Value = Format(CStr(M), "00") & ":" & Format(CStr(S), "00")
End With
DoEvents
Loop Until (Timer - t) / 60 >= CDbl(AllowedTime) Or UserForm1.Visible = False 'i.e. Cancel clicked during countdown
Unload UserForm1
Beep
MsgBox "Time is Up!"
End Sub
including those buttons? Here is the code :
Public AllowedTime As Variant
Sub Open_count ()
AllowedTime = InputBox("Enter the time interval to countdown")
If AllowedTime = "" Then Exit Sub
UserForm2.Show
End Sub
Private Sub UserForm_Initialize()
Dim M As Double, S As Double
M = Int(CDbl(AllowedTime))
S = (CDbl(AllowedTime) - Int(CDbl(AllowedTime))) * 60
With tBx1
.Value = Format(CStr(M), "00") & ":" & Format(CStr(S), "00")
End With
End Sub
I dont have that second command butto i my userform
Private Sub CommandButton1_Click()
Dim t, E, M As Double, S As Double
'AllowedTime is set in sub 'modTestUserForm' for this user form
t = Timer
Do
'next If-End If protects in case clock was started just before midnight and Timer resets during countdown
If Timer - t < 0 Then
Unload UserForm1
MsgBox "Error encountered - start again"
Exit Sub
End If
E = CDbl(Time) * 24 * 60 * 60 - t 'elapsed time in secs
M = CDbl(AllowedTime) - 1 - Int(E / 60)
S = 59 - Round((E / 60 - Int(E / 60)) * 60, 0)
With tBx1
.Value = Format(CStr(M), "00") & ":" & Format(CStr(S), "00")
End With
DoEvents
Loop Until (Timer - t) / 60 >= CDbl(AllowedTime) Or UserForm1.Visible = False 'i.e. Cancel clicked during countdown
Unload UserForm1
Beep
MsgBox "Time is Up!"
End Sub