Previous Topic

Next Topic

Sub...End Sub statement

Declares the name, arguments, and code that define a Sub procedure.

Syntax

Sub name[(arglist)]
  [statements]
  [Exit Sub]
  [statements]
End Sub

ArgList

The ArgList is made up of one or more arguments, each has the following syntax and parts:

argname1 [AS type][, argname2 [AS type] ...]

Comments

When the Sub procedure returns to the calling program, execution continues with the statement following the statement that called it.

The Exit Sub statement causes an immediate exit from a Sub procedure. A number of Exit Sub statements can appear anywhere in the procedure.

You can use the Return statement to immediately exit the procedure, as the following example shows:

Sub MySub(Q As String)
  ' ...
  Return
  ' ...
End Sub

A number of Return statements can appear anywhere in the procedure. You can mix Exit Sub and Return statements.

A Sub procedure, like a Function procedure, is a separate procedure that can take arguments and perform a series of statements. However, unlike a Function procedure, which returns a value, a Sub procedure cannot be used in an expression.

You call a Sub procedure by using the Call statement, followed by the procedure name, followed by the argument list in parentheses, in a statement. You can omit the parentheses only if you are not supplying arguments.

See Also

MaxBasic Statements

Book Contents

Book Index