O'Reilly logo

VB.NET Language in a Nutshell, Second Edition by Steven Roman PhD, Paul Lomax, Ron Petrusha

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

Timer Property

Class

Microsoft.VisualBasic.DateAndTime

Syntax

Timer

Return Value

Double representing the number of seconds that have elapsed since midnight

Description

Returns the number of seconds since midnight

Programming Tips and Gotchas

  • Timer is classified as a function in VB 6 and as a read-only property in VB.NET.

  • You can use the Timer property as an easy method of passing a seed number to the Randomize procedure, as follows:

    Randomize Timer(  )
  • The Timer property is ideal for measuring the time taken to execute a procedure or program statement, as the following snippet shows:

    Dim sStartTime As Single
    Dim i As Integer
        
    sStartTime = Timer(  )
        For i = 1 To 100
            Console.WriteLine("Hello")
        Next i
    MsgBox("Time Taken = " & Timer(  ) - sStartTime & " Seconds")

VB.NET/VB 6 Differences

While the Timer property returns a Double in VB.NET, the VB 6 Timer function returns a Single.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required