"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:
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:
2. Implicit call without the keyword "Call" - Parentheses are not allowed if there are 2 or more argument
in this syntax (very strange rule):
Both syntaxes will cause the host environment to:
- Stop execution in main code flow.
- Map data or variables based on the argument list.
- Execute the entire statement block defined inside the subroutine.
- Continue to execute main code flow.
If you want terminate a sub procedure early, you can use the "Exit" statement:
Table of Contents
About This Book
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
What Is a Procedure?
"Function" Statement and Function Call
Function Procedure Example
►"Sub" Statement and Subroutine Call
Sub (Subroutine) Procedure Example
Passing Arguments to Procedures
Example - Passing Arguments by Reference
Example - Passing Arguments by Value
Passing Arrays as Arguments
Variable Scope in Procedures
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
Creating Your Own Classes
IE Web Browser Supporting VBScript
IIS ASP Server Supporting VBScript
WSH (Windows Script Host)
PDF Printing Version