Array Function: Returns a Variant containing an array.
Array(arglist)
The required arglist argument is a comma-delimited list of values that are assigned to the elements of an array contained with the Variant. If no arguments are specified, an array of zero length is created.
Remarks
The notation used to refer to an element of an array consists of the variable name followed by parentheses containing an index number indicating the desired element. In the following example, the first statement creates a variable named A. The second statement assigns an array to variable A. The last statement assigns the value contained in the second array element to another variable.
Dim A
A = Array(10,20,30)
B = A(2) ‘ B is now 30.
Note A variable that is not declared as an array can still contain an array. Although a Variant variable containing an array is conceptually different from an array variable containing Variant elements, the array elements are accessed in the same way.
Dim Statement: Declares variables and allocates storage space
Variables declared with Dim at the script level are available to all procedures within the script. At the procedure level, variables are available only within the procedure.
You can also use the Dim statement with empty parentheses to declare a dynamic array. After declaring a dynamic array, use the ReDim statement within a procedure to define the number of dimensions and elements in the array. If you try to redeclare a dimension for an array variable whose size was explicitly specified in a Dim statement, an error occurs.
Note When you use the Dim statement in a procedure, you generally put the Dim statement at the beginning of the procedure.
The following examples illustrate the use of the Dim statement:
Dim Names(9) ‘ Declare an array with 10 elements.
Dim Names() ’ Declare a dynamic array.
Dim MyVar, MyNum ‘ Declare two variables.
ReDim Statement
Declares dynamic-array variables, and allocates or reallocates storage space at procedure level.
The ReDim statement is used to size or resize a dynamic array that has already been formally declared using a Private, Public, or Dim statement with empty parentheses (without dimension subscripts). You can use the ReDim statement repeatedly to change the number of elements and dimensions in an array.
If you use the Preserve keyword, you can resize only the last array dimension, and you can’t change the number of dimensions at all. For example, if your array has only one dimension, you can resize that dimension because it is the last and only dimension. However, if your array has two or more dimensions, you can change the size of only the last dimension and still preserve the contents of the array.
The following example shows how you can increase the size of the last dimension of a dynamic array without erasing any existing data contained in the array.
ReDim X(10, 10, 10)
. . .
ReDim Preserve X(10, 10, 15)
Caution If you make an array smaller than it was originally, data in the eliminated elements is lost.
Private Statement:
Declares private variables and allocates storage space. Declares, in a Class block, a private variable.
Private statement variables are available only to the script in which they are declared.
You can also use the Private statement with empty parentheses to declare a dynamic array. After declaring a dynamic array, use the ReDim statement within a procedure to define the number of dimensions and elements in the array. If you try to redeclare a dimension for an array variable whose size was explicitly specified in a Private, Public, or Dim statement, an error occurs.
Private MyNumber ‘ Private Variant variable.
Private MyArray(9) ‘ Private array variable.
‘ Multiple Private declarations of Variant variables.
Public Statement:
Declares public variables and allocates storage space. Declares, in a Class block, a private variable.
Public statement variables are available to all procedures in all scripts.
You can also use the Public statement with empty parentheses to declare a dynamic array. After declaring a dynamic array, use the ReDim statement within a procedure to define the number of dimensions and elements in the array. If you try to redeclare a dimension for an array variable whose size was explicitly specified in a Private, Public, or Dim statement, an error occurs.
The following example illustrates the use of the Public statement:
Public MyNumber ‘ Public Variant variable.
Public MyArray(9) ‘ Public array variable.
‘ Multiple Public declarations of Variant variables.
Public MyNumber, MyVar, YourNumber
Set Statement:
Assigns an object reference to a variable or property.
The Dim, Private, Public, or ReDim statements only declare a variable that refers to an object. No actual object is referred to until you use the Set statement to assign a specific object.
Dim fso, d, s
Set fso = CreateObject(“Scripting.FileSystemObject”)
Set d = fso.GetDrive(fso.GetDriveName(drvPath))
s = “Drive ” & UCase(drvPath) & ” – “
s = s & d.VolumeName & “<BR>”
s = s & “Free Space: ” & FormatNumber(d.FreeSpace/1024, 0)
s = s & ” Kbytes”
ShowFreeSpace = s
Is Operator:
Compares two object reference variables.
If object1 and object2 both refer to the same object, result is True; if they do not, result is False. Two variables can be made to refer to the same object in several ways.
In the following example, A has been set to refer to the same object as B:
Set A = B
The following example makes A and B refer to the same object as C:
Set A = C
Set B = C
Assignment Operator (=) Assigns a value to a variable or property.
Comparison Operators Used to compare expressions.
The Is operator has specific comparison functionality that differs from the operators in the following table. The following table contains a list of the comparison operators and the conditions that determine whether result is True, False, or Null:
Operator Description True if False if Null if
< Less than expression1 < expression2 expression1 >= expression2 expression1 or expression2 = Null
<= Less than or equal to expression1 <= expression2 expression1 > expression2expression1 or expression2 = Null
> Greater than expression1 > expression2 expression1 <= expression2 expression1 or expression2 = Null
>= Greater than or equal to expression1 >= expression2 expression1 < expression2expression1 or expression2 = Null
= Equal to expression1 = expression2 expression1 <> expression2 expression1 or expression2 = Null
<> Not equal to expression1 <> expression2 expression1 = expression2 expression1 or expression2 = Null
When comparing two expressions, you may not be able to easily determine whether the expressions are being compared as numbers or as strings.
The following table shows how expressions are compared or what results from the comparison, depending on the underlying subtype:
If Then
Both expressions are numeric Perform a numeric comparison.
Both expressions are strings Perform a string comparison.
One expression is numeric and the other is a string The numeric expression is less than the string expression.
One expression is Empty and the other is numeric Perform a numeric comparison, using 0 as the Empty expression.
One expression is Empty and the other is a string Perform a string comparison, using a zero-length string (“”) as the Empty expression.
Both expressions are Empty The expressions are equal.
Operator Precedence When several operations occur in an expression, each part is evaluated and resolved in a predetermined order called operator precedence. Parentheses can be used to override the order of precedence and force some parts of an expression to be evaluated before other parts. Operations within parentheses are always performed before those outside. Within parentheses, however, normal operator precedence is maintained.
When expressions contain operators from more than one category, arithmetic operators are evaluated first, comparison operators are evaluated next, and logical operators are evaluated last. Comparison operators all have equal precedence; that is, they are evaluated in the left-to-right order in which they appear. Arithmetic and logical operators are evaluated in the following order of precedence:
Arithmetic Comparison Logical
Negation (-) Equality (=) Not
Exponentiation (^) Inequality (<>) And
Multiplication and division (*, /) Less than (<) Or
Integer division (\) Greater than (>) Xor
Modulus arithmetic (Mod) Less than or equal to (<=) Eqv
Addition and subtraction (+, -) Greater than or equal to (>=) Imp
String concatenation (&) Is &
When multiplication and division occur together in an expression, each operation is evaluated as it occurs from left to right. Likewise, when addition and subtraction occur together in an expression, each operation is evaluated in order of appearance from left to right.
The string concatenation operator (&) is not an arithmetic operator, but in precedence it does fall after all arithmetic operators and before all comparison operators. The Is operator is an object reference comparison operator. It does not compare objects or their values; it checks only to determine if two object references refer to the same object.
IsArray Returns a Boolean value indicating whether a variable is an array.
IsArray returns True if the variable is an array; therewise, it returns False. IsArray is especially useful with variants containing arrays.
The following example uses the IsArray function to test whether MyVariable is an array:
Dim MyVariable
Dim MyArray(3)
MyArray(0) = “Sunday”
MyArray(1) = “Monday”
MyArray(2) = “Tuesday”
MyVariable = IsArray(MyArray) ‘ MyVariable contains “True”.