ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Count Timer Pause and Stop button (https://www.excelbanter.com/excel-programming/442489-count-timer-pause-stop-button.html)

[email protected]

Count Timer Pause and Stop button
 
Hello Everyone,
I am trying to build a count timer on userform. I found a code and
tried to modify as my need which will be as below. I cannot find the
way to put pause the counter timer and stop counter timer. So I need
two more button on my userform. Can anyone give me a hand on that.
Whatever I did did not work to pause the counter or stop the counter.
Thanks in advance,
have a good day
Baha

[email protected]

Count Timer Pause and Stop button
 
On May 12, 9:02*pm, " wrote:
Hello Everyone,
I am trying to build a count timer on userform. I found a code and
tried to modify as my need which will be as below. I cannot find the
way to put pause the counter timer and stop counter timer. So I need
two more button on my userform. Can anyone give me a hand on that.
Whatever I did did not work to pause the counter or stop the counter.
Thanks in advance,
have a good day
Baha


Sorry I forgot to post the code...
Option Explicit
Private dTimerEnd As Date
Dim iSecondsLeft, iSecondsLeft1 As Integer

Sub StartTimer()
Dim iSeconds, iSeconds1 As Integer
iSeconds = 10
dTimerEnd = Now + TimeSerial(0, 0, iSeconds)
UserForm1.Label1 = iSeconds
If UserForm1.Label1.Caption = "10" Then
UserForm1.Label1.Caption = "00"
End If
Application.OnTime EarliestTime:=Now + TimeValue("00:00:01"), _
procedu="CountDown"
End Sub

Sub CountDown()
iSecondsLeft = CInt((dTimerEnd - Now) * 86400)
If iSecondsLeft < 0 Then iSecondsLeft = 0
UserForm1.Label1 = iSecondsLeft
If iSecondsLeft = 0 Then
UserForm1.Label2 = UserForm1.Label2 - 1
StartTimer
End If
If iSecondsLeft 0 Then
Application.OnTime EarliestTime:=Now + TimeValue("00:00:01"), _
procedu="CountDown"
End If
If UserForm1.Label2 = 0 Then
'UserForm1.Label2 = "00"
UserForm1.Label2 = 20
UserForm1.Label3 = UserForm1.Label3 * 2
UserForm1.Label4 = UserForm1.Label4 * 2
StartTimer
End If

If Len(UserForm1.Label1) < 2 Then
UserForm1.Label1.Caption = "0" & UserForm1.Label1
End If
If Len(UserForm1.Label2) < 2 Then
UserForm1.Label2.Caption = "0" & UserForm1.Label2
End If
If UserForm1.Label1.Caption = "10" Then
UserForm1.Label1.Caption = "00"
End If
End Sub


All times are GMT +1. The time now is 01:43 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com