"Function" Statement and Function Call
This section describes how to define and invoke a function procedure. Assigning a value to the procedure name in the function procedure sets the return value.
A "Function" statement defines a function procedure with the following syntax:
function_name = return_value
where "function_name" is the name of the function, "argument_list" a list of variables used
to pass data into and/or out of the function, and "return_value" is the value to be returned explicitly
to the invoking statements.
Of course, "argument_list" is optional.
Assigning the return value to the function name is also optional. If not given, a default value
will be returned to the invoking statements. But this is not recommended.
Invoking a function procedure is simple, no need of any special statements. Just use the function
name with an argument list in any expression:
... function_name(argument_list) ...
This will cause the system to:
- Stop evaluating the expression.
- Map data or variables based on the argument list.
- Execute the entire statement block defined inside the function.
- Take the value returned in the function name.
- Continue to evaluate the expression.
If you want terminate a function 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)
Full Version in PDF/EPUB