VBScript Tutorials - Herong's Tutorial Examples - Version 5.20, by Dr. Herong Yang

What Is a Procedure?

This section describes what is a procedure and what are the two types of procedures in VBScript.

Procedure - A unit of code defined outside of the main execution code. A procedure will not be executed unless it is invoked by the main execution code or another procedure.

To learn how to use procedures in VBScript, we need to pay attentions in the following areas:

1. How to define a procedure?

2. How to invoke a procedure?

3. How to exchange data between the procedure and the invoking code?

VBScript offers two types of procedures:

1. Function Procedure - A procedure that returns a value explicitly.

2. Sub Procedure - A procedure that does not return any value explicitly.

Here is simple example of defining a function procedure, invoking a procedure, and exchanging data with a procedure:

   Function sqrt(x)
      sqrt = x^0.5
   End Function

   y = sqrt(2)

Table of Contents

 About This Book

 Introduction of VBScript - Visual Basic Scripting Edition

 Variant Data Type, Subtypes, and Literals

 Arithmetic Operations

 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

 Built-in Functions

 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)

 References

 Printable Copy - PDF Version

What Is a Procedure? - Updated in 2015, by Dr. Herong Yang