Siebel VB Language Reference > VB Language Reference >

Exit Statement


This standard VB statement terminates loop statements or transfers control to a calling procedure.

Syntax

Exit {Do | For | Function | Sub}

Returns

Not applicable

Usage

Use Exit Do inside a Do...Loop statement. Use Exit For inside a For...Next statement. When the Exit statement is executed, control transfers to the statement after the Loop or Next statement. When used within a nested loop, an Exit statement moves control out of the immediately enclosing loop.

Use Exit Function inside a Function...End Function procedure. Use Exit Sub inside a Sub...End Sub procedure.

Example

This example uses the On Error statement to trap run-time errors. If there is an error, the program execution continues at the label "Debugger." The example uses the Exit statement to skip over the debugging code when there is no error.

Sub Button_Click
   Dim msgtext, userfile
   On Error GoTo Debugger
   msgtext = "Enter the filename to use:"
   userfile = "c:\temp\trace.txt"
   Open userfile For Input As #1
   ' ....etc....
   Close #1
done:
   Exit Sub
Debugger:
   msgtext = "Error " & Err & ": " & Error$
      Resume done
End Sub

See Also

Do...Loop Statement
Function...End Function Statement
Sub...End Sub Statement

Siebel VB Language Reference