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.