Skip to content

Delay Methods Reference

📋 Method List

MethodDescription
CallbackSet callback mode (chainable)
SyncSet synchronous wait mode (chainable)
CountDownStart countdown
CancelCancel delay

🔗 Callback Method

Description

Sets callback mode. After delay ends, automatically calls the specified method of the specified object. Supports up to 9 parameters.

Syntax

vb
Public Function Callback(ByVal CallbackObject As Object, ByVal ProcName As String, ParamArray P()) As cDelay

Parameters

ParameterTypeDescription
CallbackObjectObjectObject containing the callback method
ProcNameStringCallback method name
P()ParamArrayVariable parameters, up to 9

Return Value

Returns the object itself for chainable calls.

Example

Callback Without Parameters

vb
Private Delay As cDelay

Private Sub Test1()
    Set Delay = New cDelay
    Delay.Callback(Me, "DoSomething").CountDown 1000
End Sub

Public Sub DoSomething()
    Debug.Print "Executed!"
End Sub

Callback With Parameters

vb
Private Sub Test2()
    Set Delay = New cDelay
    Delay.Callback(Me, "ProcessData", "username", 25, True).CountDown 2000
End Sub

Public Sub ProcessData(ByVal name As String, ByVal age As Long, ByVal active As Boolean)
    Debug.Print name & ", " & age & ", " & active
End Sub

⏱️ Sync Method

Description

Sets synchronous wait mode. After calling CountDown, it blocks and waits, but processes the message queue, so UI doesn't freeze.

Syntax

vb
Public Function Sync() As cDelay

Return Value

Returns the object itself for chainable calls.

Example

vb
Private Sub TestSync()
    Dim Delay As New cDelay
    
    Debug.Print "Start: " & Now
    Delay.Sync().CountDown 3000  ' Wait 3 seconds
    Debug.Print "End: " & Now    ' Executes after 3 seconds
End Sub

⚠️ Notes

  • In sync mode, wait can be cancelled via Cancel method
  • Use IsCancelled property to determine if cancelled or completed normally
  • Message queue is processed during wait, UI stays responsive

▶️ CountDown Method

Description

Starts countdown. Behavior depends on current mode:

  • Event/Callback mode: Starts Windows timer
  • Sync mode: Enters message loop wait

Syntax

vb
Public Sub CountDown(ByVal Milliseconds As Long)

Parameters

ParameterTypeDescription
MillisecondsLongDelay milliseconds

Example

vb
' Event mode
Delay.CountDown 5000  ' Triggers OnTime event after 5 seconds

' Callback mode (need to call Callback first)
Delay.Callback(Me, "OnDelay").CountDown 3000

' Sync mode (need to call Sync first)
Delay.Sync().CountDown 2000

❌ Cancel Method

Description

Cancels the current delay operation. Stops timer and triggers OnCancel event.

Syntax

vb
Public Sub Cancel()

Example

vb
Private WithEvents Delay As cDelay

Private Sub cmdStart_Click()
    Set Delay = New cDelay
    Delay.CountDown 10000  ' 10 second delay
End Sub

Private Sub cmdCancel_Click()
    Delay.Cancel  ' Cancel delay
End Sub

Private Sub Delay_OnCancel()
    Debug.Print "Delay cancelled"
End Sub

📌 Usage Scenarios Summary

Delayed Operation Execution

vb
' Execute cleanup after 3 seconds
Delay.Callback(Me, "DoCleanup").CountDown 3000

Delayed Wait (Keep UI Responsive)

vb
Private Sub LongOperation()
    ' First step
    DoStep1
    
    ' Wait 2 seconds (UI stays responsive)
    Delay.Sync().CountDown 2000
    
    ' Second step
    DoStep2
End Sub

Cancellable Delay

vb
Private Sub StartDelayedTask()
    Set Delay = New cDelay
    Delay.CountDown 5000
End Sub

Private Sub CancelTask()
    If Not Delay Is Nothing Then
        Delay.Cancel
    End If
End Sub

Private Sub Delay_OnTime()
    Debug.Print "Delayed task executed"
End Sub

Private Sub Delay_OnCancel()
    Debug.Print "Delayed task cancelled"
End Sub

Last Updated: 2026-05-17

VB6 and LOGO copyright of Microsoft Corporation