Returns a Double value representing the number of seconds elapsed since midnight.
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 ' Set end time for 5-second duration. finish = start + 5.0 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 thenamespace, because Timer is also a defined class in the , , and namespaces.
Assembly: Visual Basic Runtime Library (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.