VBScript Tutorials - Herong's Tutorial Examples - v6.02, by Herong Yang
Passing Arguments to Procedures
This section describes rules on how arguments can be passed from the calling code into the called procedure by reference (the default) or by value.
As shown in previous examples, passing arguments to procedures seems to be a simple job. But it may cause confusion if you don't following the rules. VBScript has the following rules on passing arguments to function and subroutine procedures:
1. By default, arguments are passed by reference. In this case, an argument name can be used as a variable that referring (sharing) the same data as the calling code.
2. But, arguments can be passed by value, if you put the key word "ByVal" before the argument name. In this case, an argument name can be used as a variable that contains a copy of the data provided by the calling code.
3. Of course, you put the word "ByRef" before an argument name to declare a pass-by-reference argument explicitly.
4. A pass-by-reference argument can be used to allow the procedure to alter data that is associated with a variable in the calling code. This allows the procedure to output data back to the calling code.
5. A pass-by-value argument is safer than a pass-by-reference argument, because the procedure only gets a copy of the data. Any changes to that data will not affect the original data in the calling code.
6. Arrays can be passed by reference.
7. Arrays can also be passed by value. In this case, the procedure will get a copy of the array.
8. I don't know how to specify an array as the return value of a function procedure.
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