Set Time Method
The Set Time method sets the computer time. It does not return a value.
If the value in the expression argument is not already a date variable type, then this method attempts to convert it to a valid time. It recognizes the time separator characters defined in the International section of the Microsoft Windows Control Panel. For more information, see Variants.
Format
Time[$] = expression
The following table describes the arguments that you can use with this method.
Argument | Description |
---|---|
expression |
An expression that evaluates to a valid time. |
Usage of the Dollar Sign
If you include the dollar sign ($), then the following items apply:
The value in the expression argument must evaluate to a string that uses one of the following forms:
hh. Sets the time to hh hours, 0 minutes, and 0 seconds.
hh:mm. Sets the time to hh hours, mm minutes, and 0 seconds.
hh:mm:ss. Sets the time to hh hours, mm minutes, and ss seconds.
It uses a 24 hour clock. For example, 6:00 P.M. is 18:00:00.
If you do not include the dollar sign ($), then the following items apply:
The expression argument can include a string that contains a valid date, or a date variable type of 8 (string).
It accepts 12 hour and 24 hour clocks.
Example
The following example modifies the time of the computer clock:
Sub Button_Click
Dim newtime As String
Dim answer As String
On Error Resume Next
i:
newtime = "5:30"
answer = PM
If answer = "PM" or answer = "pm" then
newtime = newtime &"PM"
End If
Time = newtime
If Err <> 0 then
Err = 0
Goto i
End If
End Sub