VB6Parse / Library / System Interaction / stop

VB6 Library Reference

Stop Statement

Suspends execution.

Syntax

Stop

Remarks

Common Uses

Examples

Simple Stop

Sub Test()
    Dim x As Integer
    x = 10
    Stop  ' Execution pauses here in IDE
    x = x + 5
End Sub

Conditional Stop for Debugging

Sub ProcessData(value As Integer)
    If value < 0 Then
        Stop  ' Pause when invalid data is encountered
    End If
    ' Process value
End Sub

Stop in Loop for Specific Iteration

For i = 1 To 100
    If i = 50 Then
        Stop  ' Pause at iteration 50
    End If
    ProcessItem i
Next i

Stop on Error Condition

Sub CalculateTotal()
    Dim total As Double
    total = GetSubtotal()
    If total < 0 Then
        Stop  ' Investigate negative total
    End If
    SaveTotal total
End Sub

Multiple Stop Statements for Debugging Path

Function ValidateData(data As String) As Boolean
    Stop  ' Entry point
    If Len(data) = 0 Then
        Stop  ' Empty string case
        ValidateData = False
        Exit Function
    End If
    Stop  ' Normal processing
    ValidateData = True
End Function

Stop in Select Case

Select Case userType
    Case 1
        ProcessAdmin
    Case 2
        ProcessUser
    Case Else
        Stop  ' Unknown user type - investigate
End Select

Stop with Error Handler

On Error GoTo ErrorHandler
ProcessData
Exit Sub
ErrorHandler:
    Stop  ' Pause to examine error
    MsgBox Err.Description
End Sub

Stop in Class Module

Private Sub Class_Initialize()
    Stop  ' Verify initialization sequence
    InitializeProperties
End Sub

Stop Before Critical Operation

Sub DeleteAllRecords()
    Stop  ' Verify this operation should proceed
    Dim rs As Recordset
    Set rs = db.OpenRecordset("Data")
    Do While Not rs.EOF
        rs.Delete
        rs.MoveNext
    Loop
End Sub

Stop in Property Procedure

Public Property Let Value(ByVal newValue As Integer)
    If newValue < 0 Then
        Stop  ' Negative value assigned
    End If
    m_Value = newValue
End Property

Stop with DoEvents

For i = 1 To 1000
    DoEvents
    ProcessItem i
    If ShouldDebug Then
        Stop  ' Conditional pause
    End If
Next i

Stop in Event Handler

Private Sub Form_Load()
    Stop  ' Debug form initialization
    InitializeControls
    LoadData
End Sub

Stop with Assert-like Check

Sub ProcessArray(arr() As Integer)
    If UBound(arr) < LBound(arr) Then
        Stop  ' Invalid array bounds
    End If
    For i = LBound(arr) To UBound(arr)
        ProcessItem arr(i)
    Next i
End Sub

Important Notes

Best Practices

Differences from End

See Also

References

← Back to System Interaction | View all statements