[RESOLVED] Showing timers in VBA
I have got a ten second timer working in my program using the code,
VB Code:
Application.Wait Now + TimeValue("00:00:10")
I now want to show the seconds on screen as they are going down. I came up with the following idea to do this,
VB Code:
Application.Wait Now + TimeValue("00:00:10")
ClockTimer = 0
Do
ClockTimer = ClockTimer + 1
TimeValue ("00:00:ClockTimer")
lblTimer.Caption = ClockTimer
Loop Until ClockTimer = 10
i now realise how stupid this is since it waits till the ten seconds are up to run the loop, and the code doesn't work anyways, but can anyone think of a way to adapt my code slightly to make it work?
Re: Showing timers in VBA
Just use a simple loop, with a one second delay for each iteration, eg:
VB Code:
Dim intCount as Integer
For intCount = 10 to 1 Step -1
lblTimer.Caption = CStr(intCount)
Application.Wait Now + TimeValue("00:00:01")
Next intCount
lblTimer.Caption = "0"
Re: Showing timers in VBA
Quote:
Originally Posted by si_the_geek
Just use a simple loop, with a one second delay for each iteration, eg:
VB Code:
Dim intCount as Integer
For intCount = 10 to 1 Step -1
lblTimer.Caption = CStr(intCount)
Application.Wait Now + TimeValue("00:00:01")
Next intCount
lblTimer.Caption = "0"
Thanks for the help I think that's almost it, but in my label "10" appears and then when 10 seconds have passed a "0" appears, I want it to show all the numbers.
Any ideas what to do?
Thanks in advance.
Re: Showing timers in VBA
Throw a DoEvents in the loop to allow the CPU to update the label caption withthe changes.
VB Code:
Dim intCount as Integer
For intCount = 10 to 1 Step -1
lblTimer.Caption = CStr(intCount)
Application.Wait Now + TimeValue("00:00:01")
DoEvents
Next intCount
lblTimer.Caption = "0"
Re: Showing timers in VBA
Quote:
Originally Posted by RobDog888
Throw a DoEvents in the loop to allow the CPU to update the label caption withthe changes.
VB Code:
Dim intCount as Integer
For intCount = 10 to 1 Step -1
lblTimer.Caption = CStr(intCount)
Application.Wait Now + TimeValue("00:00:01")
DoEvents
Next intCount
lblTimer.Caption = "0"
Thanks a load! :)