Problem solve Get help with specific problems with your technologies, process and projects.

Hacking time down to fractions

This tio shows how to hack a time down to fractions.

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

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
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.

Dig Deeper on .NET development community

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.