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

This was first published in March 2001

There are Comments. Add yours.

TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
Sort by: OldestNewest

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

Disclaimer: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.