Stop a timer

  • Thread starter Thread starter Michael Singmin
  • Start date Start date
M

Michael Singmin

Hello Group,

I use this simple code for a countdown timer where [A1] holds the
initial secs.

t = [A1]
For s = t To 0 Step -1
[A1] = s
Application.Wait Now + TimeValue("00:00:01")
Next

If I want to abort this routine, I use the inelegant Ctrl Break.

I created a form button with code
[A1]=0 but this button never interupts the timer.

I have tried inserting Doevents but no effect.

Any other ideas ?

Michael Singmin
 
try the Application OnTime method. It can run a procedure
and be stopped too.

OnTime Method Example

This example runs my_Procedure 15 seconds from now.

Application.OnTime Now + TimeValue
("00:00:15"), "my_Procedure"
This example runs my_Procedure at 5 P.M.

Application.OnTime TimeValue("17:00:00"), "my_Procedure"
This example cancels the OnTime setting from the previous
example.

Application.OnTime EarliestTime:=TimeValue("17:00:00"), _
Procedure:="my_Procedure", Schedule:=False
 
The following worked for me. Tester11 was assigned to a button from the
forms toolbar.

Sub Tester11()
[A1] = 0
End Sub


Sub Tester10()
t = [A1]
For s = t To 0 Step -1
DoEvents
If [A1] = 0 Then Exit Sub
DoEvents
Application.Wait Now + TimeValue("00:00:01")
DoEvents
'Range("A2").Value = s
Next

End Sub
 
Hello Smalltalk,
I have used OnTime before for countdown timers.
With my VBA programming, I always try to use simpler routines
that will accomplish the job.

Hello Tom,
Thank you for your solution.
It was the first DoEvents and test that was needed.
It was also bad programming on my part, to alter the countdown
cell with my form button. Better test elsewhere.
Much appreciated,

MIchael Singmin
=============================================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top