|
-
Feb 18th, 2006, 11:42 AM
#1
Thread Starter
Member
[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?
-
Feb 18th, 2006, 12:07 PM
#2
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"
-
Feb 18th, 2006, 04:37 PM
#3
Thread Starter
Member
Re: Showing timers in VBA
 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.
-
Feb 18th, 2006, 04:38 PM
#4
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"
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Feb 18th, 2006, 04:46 PM
#5
Thread Starter
Member
Re: Showing timers in VBA
 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!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|