Timer.CallLater

From Xojo Documentation

Shared Method

Timer.CallLater(afterMilliseconds As Integer, method As Timer.TimerCallLater)

New in 2019r2

Supported for all project types and targets.

Used to call a method (without parameters) once after the specified delay in milliseconds.


Shared Method

Timer.CallLater(afterMilliseconds As Integer, method As Timer.TimerCallLaterWithValue, value As Variant)

New in 2019r2

Supported for all project types and targets.

Used to call a method (with a parameter) once after the specified delay in milliseconds.

Notes

To pass a parameter to your CallLater method, the method signature must exactly match the Timer.TimerCallLaterWithValue Delegate signature. Specifically this means that the method must have a single parameter that is of type Variant. No other type will work (even if it can convert to Variant).

Refer to the sample below to see how this is done.

Sample Code

Suppose you want to display some help text for a few seconds and then hide it. You can do this by creating a method to clear a Label (ClearLabel):

Sub ClearLabel
MyLabel.Text = ""
End Sub

In the initial method, you set the Label help text and then use CallLater to set it to clear it after 2 seconds:

MyLabel.Text = "Help text goes here"
Timer.CallLater(2000, AddressOf ClearLabel)

Suppose you want to display some help text for a few seconds and then replace it with different text. You can do this by creating a method that takes the text to display as a parameter (SetLabel). Remember the Delegate method parameter must be of type Variant as shown here:

Sub SetLabel(helpText As Variant)
MyLabel.Text = helpText
End Sub

In the initial method, you set up the Label help text and use CallLater to change it after 2 seconds:

MyLabel.Text = "First help text goes here"
Timer.CallLater(2000, AddressOf SetLabel, "Second help text goes here")