VBScript Tutorials - Herong's Tutorial Examples - v6.02, by Herong Yang
"Dim x()" - Declaring Array Variables
This section provides an introduction and examples on how to declare array variables with fixed sizes or dynamic sizes.
VBScript supports 2 ways to declare an array variable:
1. Explicit Declaration with Fixed Size - Using "Dim" statement with size included as:
Dim array_name(upper_bound)
where "upper_bound" is positive integer specifying the upper bound of the element index. Array declared in this way has a fixed size (number of elements). By default, the size of an array is the upper bound plus 1, because index starts from 0. This size can not be changed.
2. Explicit Declaration with Dynamic Size - Using "Dim" and "ReDim" statements as shown in the following syntax:
Dim array_name() ... ReDim [Preserve] variable_name(upper_bound) ...
The "Dim" statement declares an array variable without any upper bound. The "ReDim" statement resets the upper bound to a new value. The optional key word "Preserve" specifies that all old elements must be preserved when resetting the array size. Array declared in this way can be resized at any time.
VBScript offers some other useful functions and statements for you to work with arrays:
See sections below for details and examples on those functions and statements.
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
►"Dim x()" - Declaring Array Variables
"x(i)" - Accessing Array Elements with Indexes
"Dim x(n)" - Fixed-Size Array Example
"Dim x()" - Dynamic-Size Array Example
"Erase" Statement - Removing All Elements in an Array
Data Type "Variant()" - Array of Variant Values
Array References and Array Assignment Statements
Conditional Statements - "If ... Then" and "Select Case"
Loop Statements - "For", "While", and "Do"
"Function" and "Sub" 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