VBScript Tutorials - Herong's Tutorial Examples - v6.02, by Herong Yang
"Sub" Statement and Subroutine Call
This section describes how to define and invoke a subroutine procedure. There is no way to specify a return value in a subroutine procedure.
A subroutine procedure is similar to a function procedure. It can be defined with the "Sub" statement:
Sub sub_name(argument_list) statement_block End Sub
where "sub_name" is the name of the sub procedure (subroutine), and "argument_list" a list of variables used to pass data into and/or out of the subroutine.
Of course, "argument_list" is optional.
Notice that subroutine does not return any values.
Invoking a subroutine is different than a function procedure. You can use one of the two syntaxes below:
1. Explicit call with a "Call" statement:
Call sub_name(argument_list)
2. Implicit call without the keyword "Call" - Parentheses are not allowed if there are 2 or more argument in this syntax (very strange rule):
sub_name argument sub_name(argument) sub_name argument_list
Both syntaxes will cause the host environment to:
If you want terminate a sub procedure early, you can use the "Exit" statement:
Exit Sub
Table of Contents
Introduction of VBScript - Visual Basic Scripting Edition
Variant Data Type, Subtypes, and Literals
Numeric Comparison Operations and Logical Operations
String Operations - Concatenation and Comparison
Variable Declaration and Assignment Statement
Expression and Order of Operation Precedence
Statement Syntax and Statement Types
Array Data Type and Related Statements
Array References and Array Assignment Statements
Conditional Statements - "If ... Then" and "Select Case"
Loop Statements - "For", "While", and "Do"
►"Function" and "Sub" Procedures
"Function" Statement and Function Call
►"Sub" Statement and Subroutine Call
Sub (Subroutine) Procedure Example
Passing Arguments to Procedures
Example - Passing Arguments by Reference
Example - Passing Arguments by Value
Example - Variable Scope in Procedures
Inspecting Variables Received in Procedures
Error Handling Flag and the "Err" Object
Regular Expression Pattern Match and Replacement
scrrun.dll - Scripting Runtime DLL Library
IE Web Browser Supporting VBScript