Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default count down timer in text box


Hello All, I'm have a difficult time to make a count down timer in
text box. Basically I run a While loop, that does some testing.
Suring that while look I'd like a text box count down so that theuse
knows something is happening

bStopped = False 'Estop control
' Wait 10 sec
InitialTime = TIME
FinalTime = InitialTime + #12:00:10 AM#
While InitialTime < FinalTime And Not bStopped
TimerTime = FinalTime - InitialTime
lblOK.Text = TimerTime
'...
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,163
Default count down timer in text box

There are 2 separate issues with your code:
1) The text in your label will not be updated unless you let Excel redraw it
- you can accomplish this with a DoEvents statement in your loop. Also, I
would suggest you format the time text or it will show as a decimal value.
2) There is a problem in how the loop is set up: it will not stop after 10
seconds (Consider: InitialTime is always less than FinalTime, right?). Same
issue in how you are calculating the elapsed time to display - use the
current time (Time) in the calculations instead.

Here is a modified version:
bStopped = False 'Estop control
OldText = "" ' used to see when timer text has changed (see below)
' Wait 10 sec
InitialTime = Time
FinalTime = InitialTime + #12:00:10 AM#
While Time < FinalTime And Not bStopped
TimerTime = Time - InitialTime
' above calculation gives elapsed time;
' use FinalTime - Time if you want instead a "countdown" timer
lblOK.Text = Format(TimerTime, ":ss")
' Use DoEvents to allow Excel to update the label
' but if loop runs fast, constant redraw creates flicker
' so only redraw when necessary - when text changes
If lblOK.Text < OldText Then DoEvents
OldText = lblOK.Text ' reset OldText to track text changes on next loop
....
Wend

--
- K Dales


"jimbo_jones" wrote:


Hello All, I'm have a difficult time to make a count down timer in a
text box. Basically I run a While loop, that does some testing.
Suring that while look I'd like a text box count down so that theuser
knows something is happening

bStopped = False 'Estop control
' Wait 10 sec
InitialTime = TIME
FinalTime = InitialTime + #12:00:10 AM#
While InitialTime < FinalTime And Not bStopped
TimerTime = FinalTime - InitialTime
lblOK.Text = TimerTime
'...

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default count down timer in text box

Thanks K Dales, I just started programming in Excel VBA and also just
found Google.Groups, which has a lot of information!

K Dales wrote:
There are 2 separate issues with your code:
1) The text in your label will not be updated unless you let Excel redraw it
- you can accomplish this with a DoEvents statement in your loop. Also, I
would suggest you format the time text or it will show as a decimal value.
2) There is a problem in how the loop is set up: it will not stop after 10
seconds (Consider: InitialTime is always less than FinalTime, right?). Same
issue in how you are calculating the elapsed time to display - use the
current time (Time) in the calculations instead.

Here is a modified version:
bStopped = False 'Estop control
OldText = "" ' used to see when timer text has changed (see below)
' Wait 10 sec
InitialTime = Time
FinalTime = InitialTime + #12:00:10 AM#
While Time < FinalTime And Not bStopped
TimerTime = Time - InitialTime
' above calculation gives elapsed time;
' use FinalTime - Time if you want instead a "countdown" timer
lblOK.Text = Format(TimerTime, ":ss")
' Use DoEvents to allow Excel to update the label
' but if loop runs fast, constant redraw creates flicker
' so only redraw when necessary - when text changes
If lblOK.Text < OldText Then DoEvents
OldText = lblOK.Text ' reset OldText to track text changes on next loop
...
Wend

--
- K Dales


"jimbo_jones" wrote:


Hello All, I'm have a difficult time to make a count down timer in a
text box. Basically I run a While loop, that does some testing.
Suring that while look I'd like a text box count down so that theuser
knows something is happening

bStopped = False 'Estop control
' Wait 10 sec
InitialTime = TIME
FinalTime = InitialTime + #12:00:10 AM#
While InitialTime < FinalTime And Not bStopped
TimerTime = FinalTime - InitialTime
lblOK.Text = TimerTime
'...


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default count down timer in text box


I've searched on this topic, but the code I've found is extremely long,
for somethins that seems very simple. Can someone tell me if the above
idea will take more than 10 lines of code? Thanks.


--
jimbo_jones
------------------------------------------------------------------------
jimbo_jones's Profile: http://www.excelforum.com/member.php...o&userid=27244
View this thread: http://www.excelforum.com/showthread...hreadid=471899

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
45 Day Count Down Timer da_bigone Excel Worksheet Functions 1 August 30th 09 11:43 AM
count down timer NED Excel Discussion (Misc queries) 3 December 11th 07 12:39 PM
count day timer NED Excel Discussion (Misc queries) 3 December 11th 07 12:38 PM
Count Down Timer in 1 sec. increments Bob[_48_] Excel Programming 1 January 21st 04 03:51 PM
Count Down Timer (Seconds) boblauder Excel Programming 1 January 21st 04 02:55 PM


All times are GMT +1. The time now is 07:33 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"