Description
The Sub statement declares the name, arguments, and code that form the body of a Sub procedure.
This statement has the following form:
[Public [Default] | Private] Sub name [(arglist)]
[statements]
[Exit Sub]
[statements]
End Sub
Parameter | Description |
---|---|
Public | (optional) A keyword that specifies that the constant is available to all procedures in all scripts |
Default | (optional) A keyword that is used only with the Public keyword in a Class block to indicate that the
Sub procedure is the default method for the class. An error occurs if more than one Default procedure is specified in a class. |
Private | (optional) A keyword that specifies that the constant is only available within the script where the declaration is made |
name | (required) Specifies the name of the sub Note: name must follow the standard variable naming conventions |
arglist | Specifies a list of variables representing arguments that are passed to the Sub procedure when it is called This argument has the following syntax and parts: [ByVal | ByRef] varname[( )] ByVal - Indicates that the argument is passed by value ByRef - Indicates that the argument is passed by reference (if both ByVal and ByRef are omitted, the default is ByRef) varname - Specifies the name of the variable representing the argument; follows standard variable naming conventions Note: Commas separate multiple variables |
statements | Any group of statements to be executed within the body of the Sub procedure |
Examples
The following example shows the basic use of this statement:
DisplaySum 1, 2
Sub DisplaySum(value1, value2)
Dim sum
sum = value1 + value2
MsgBox "The sum is: " & sum
End Sub
This produces the following result (each line in a separate pop-up message box):
3
Miscellaneous Information
Supported in Version: | 1.0 |
---|