Hacking time down to fractions
Phil Lenoir
Want to really get down to instants? This tip from reader Phil Lenoir tells you how.
The only way you can access fractions of a second in VB is using a Timer, Right? Wrong.
Use this simple technique to access time down to the resolution of the PC timer interrupt. It relies on the fact that Microsoft's internal time format is stored as a Double-precision number representing the number of years since 1900.
This code will pause for the requested fraction of a second:
Public Sub Pause(dblHowLong As Double) Dim dblPauseUntil As Double dblPauseUntil = CDbl(Now) + dblHowLong While cDbl(Now) < dblPauseUntil DoEvents Wend End Sub
Phil Lenoir is a Contractor located in Oakville, Ontario, Canada.
Did you like this tip? Why not let us know? Email to sound off, or visit our tips page to rate this, and other tips.
Related book
David McCarter's VB Tips and Techniques
Author: David McCarter
Summary:
The author provides hard to find coding tips and
techniques that span the gamut for Visual Basic professionals. Tips
that could save hours of work and increase productivity. While there
are many books on how to learn Visual Basic, none focus on the "bite
sized" tips and techniques that maximize a Visual Basic professional?s
productivity in the real, day-to-day, programming world.
This was first published in March 2001