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 6Timer
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 .NETGetTimer
function and Timer property return a Double.
See Also
Get VB .NET Language in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.