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

GetTimer Function

Class

Microsoft.VisualBasic.VBMath

Syntax

GetTimer(  )

Return Value

A Double indicating the number of seconds

Description

Returns the number of seconds since midnight

Programming Tips and Gotchas

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

    Randomize GetTimer(  )
  • The GetTimer function is ideal for measuring the time taken to execute a procedure or block of code, as the following snippet shows:

    Dim dblStartTime As Double
    Dim i As Integer
    
    dblStartTime = Timer(  )
    For I = 1 to 100
       Console.WriteLine("Hello")
    Next
    Console.WriteLine("Time Taken = " & GetTimer(  ) - _
                      dblStartTime & " Seconds")

VB.NET/VB 6 Differences

  • The GetTimer function is new to VB.NET. However, it is functionally identical to the VB 6 Timer function (and VB.NET Timer property), which continues to be supported.

  • In contrast to the VB 6 Timer function, which returned a Single, the VB.NET GetTimer function and Timer property return a Double.

See Also

Timer Property

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