From: baha17 on
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
From: baha17 on
On May 12, 9:02 pm, "bah...(a)gmail.com" <bah...(a)gmail.com> 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"), _
procedure:="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"), _
procedure:="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
 | 
Pages: 1
Prev: sendkeys
Next: Count Timer Pause and Stop button