Visual Basic Explorer
Visual Basic Explorer
 Navigation
 Home


 Coding
 Source Code

 FAQ Center

 VB Tips

 Downloads

 ToolBox

 Tutorials

 VB Games

 VB News

 VB Award

 VB Forums



 Affiliates
 Planet Source Code

 Rent a Coder

 DirectX4VB


 Misc
 Search

 Feedback

 Advertise

 About


Need to hire
a VB coder?

Please support our sponsor:

 Home 
 Site Map 
 Forums 
 News 
 Feedback 

Timers & Timing in VB

I see lots of timing related questions on VB forums and so decided to create a seperate category for issues related to timing. These may involve the Timer Control, API, and will probably contain some related issues like creating a pause. However, if you are looking for code to format strings in 00:00 for example this is really more related to strings -and that's where you'll find it.


'----------------------------------
'Burt Abreu -One way to time a loop 
'if you don't need millisecond resolution 
'----------------------------------
Dim BeginTime As Date
Dim FinishTime As Date
Dim ElapsedTime As Long

'Get the beginning time
BeginTime = Now   

Do
'Your loop code...
Loop

'Get the time after you exit the loop
FinishTime = Now  

'Figure how many seconds between them
ElapsedTime = DateDiff("s", BeginTime, FinishTime)     

'Display like this or with debug
lblStart.Caption = BeginTime
lblFinish.Caption = FinishTime
lblElapsed.Caption = "Elapsed time in seconds " & ElapsedTime

End Sub

'-----------------------------------
'Francis J. Loh  Francis.Loh@unisys.com
'Instead of writing a Pause function with 
'the timer, just use the API...
'-----------------------------------
'It should be clear that the Sleep API function 
'freezes your app for the milliseconds specified
'completely. MS KB Article ID Q158175 
'has more information about this. 
'Basically, if you want to pause to allow your 
'application to finish a process in it's thread
'use a timer loop with doevents. If you're trying 
'to wait for an external process to end or just 
'simply wait use Sleep.  


Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

And call it like so...

Sleep (3000)  '// Will pause for 3 seconds




Home | About | What's New | Source Code | FAQ | Tips & Tricks | Downloads | ToolBox | Tutorials | Game Programming | VB Award | Search | VB Forums | Feedback | VBNews | Copyright & Disclaimer | Advertise | Privacy Policy |

Quick searches: Site Search | Advanced Site Search 

Copyright 2002 by Exhedra Solutions, Inc.
By using this site you agree to its terms and conditions
VB Explorer and VBExplorer.com are trademarks of Exhedra Solutions, Inc.