Visual Basic Language Reference  

Timer Property

Returns a Double value representing the number of seconds elapsed since midnight.

ReadOnly Public Property Timer() As Double

Remarks

The Timer property returns both the seconds and the milliseconds since midnight. The seconds are in the integral part of the return value, and the milliseconds are in the fractional part.

Example

This example uses the Timer property to pause the application. It can perform other processing during the pause.

Public Sub WaitFiveSeconds()
   If TimeOfDay >= #11:59:55 PM# Then
      MsgBox("The current time is within 5 seconds of midnight" & _
         vbCrLf & "The timer returns to 0.0 at midnight")
      Return
   End If
   Dim Start, Finish, TotalTime As Double
   If (MsgBox("Press Yes to pause for 5 seconds", MsgBoxStyle.YesNo)) = _
      MsgBoxResult.Yes Then
      Start = Microsoft.VisualBasic.DateAndTime.Timer
      Finish = Start + 5.0   ' Set end time for 5-second duration.
      Do While Microsoft.VisualBasic.DateAndTime.Timer < Finish
         ' Do other processing while waiting for 5 seconds to elapse.
      Loop
      TotalTime = Microsoft.VisualBasic.DateAndTime.Timer - Start
      MsgBox "Paused for " & TotalTime & " seconds"
   End If
End Sub

Note that you must qualify the Timer property with the Microsoft.VisualBasic namespace, because Timer is also a defined class in the System.Threading, System.Timers, and System.Windows.Forms namespaces.

Requirements

Namespace: Microsoft.VisualBasic

Module: DateAndTime

Assembly: Microsoft Visual Basic .NET Runtime (in Microsoft.VisualBasic.dll)

Because Timer is a member of a module, rather than of a class, you do not need to create an object on which to access Timer.

See Also

Randomize Statement | TimeOfDay Property | Today Property | System Namespace | System.Windows.Forms Namespace | DateTime Structure | ArgumentException Class | ArgumentOutOfRangeException Class