Timer Property


Timer Property

Class

Microsoft.VisualBasic.DateAndTime

Syntax

     Dim result As Double = DateAndTime.Timer 

Description

The Timer property returns the number of seconds since midnight.

Usage at a Glance

  • The Timer property is useful as a seed value for the Randomize procedure:

         Randomize Timer 

  • The Timer property is useful for measuring the time taken to execute a procedure or block of code:

         Dim startTime As Double     Dim counter As Integer     startTime = Timer     For counter = 1 To 100        Console.WriteLine("Hello")     Next counter     MsgBox("Time Taken = " & Timer - startTime & " Seconds") 

    However, this type of code will sometimes fail, since the second reading of the Timer property may sometimes be less than the first. This occurs when the first reading occurs before midnight, but the second one is after midnight.

Version Differences

  • In VB 6, Timer was classified as a function; it is a read-only property in .NET. Also, the VB 6 version returned a Single, while the .NET version returns a Double.

  • The 2005 release of VB includes a new My.Computer.Clock.TickCount property, which returns the number of milliseconds since midnight.




Visual Basic 2005(c) In a Nutshell
Visual Basic 2005 in a Nutshell (In a Nutshell (OReilly))
ISBN: 059610152X
EAN: 2147483647
Year: 2004
Pages: 712

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net