Schongar P.VBScript unleashed.1997
.pdfThe equal to operator's usage is
expr1 = expr2
and a True result is yielded when expr1 is arithmetically equal to expr2.
<> (Not Equal to) Operator
The not equal to operator's usage is
expr1 <> expr2
and a True result is yielded when expr1 is arithmetically not equal to expr2.
Is Operator
The Is operator compares two object reference variables. Its usage is
obj1 Is obj2
where obj1 and obj2 are object names. If obj1 and obj2 both refer to the same object, the condition is True. Two variables can be made to refer to the same object by using the Set statement.
Statements
This section describes the statement syntax for the VBScript language. In the descriptions the use of brackets ([]) indicates an optional entry or keyword.
Call Statement
The Call statement transfers control to a Sub procedure or Function procedure. Its usage is
Call name ([[ByVal] arg1, [ByVal] arg2, ... [ByVal] argn])
[result =] name [[ByVal] arg1, [ByVal] arg2, ... [ByVal] argn]
where name is the name of the procedure to call, arg1 through argn are a comma-delimited list of expressions to pass to the procedure, and result is any numeric variable. If the ByVal keyword precedes a variable in the argument list , the argument is being passed to the procedure by value and the procedure being called may change the value of the variable. In the first syntax, the argument list must be enclosed in parentheses and a result is not available.
involved. Its usages are
Exit Do
Exit For
Exit Function
Exit Sub
For...Next Statement
The For...Next loop repeats a group of statements a specified number of times and optionally varies a variable within the loop. Its usage is
For count = start To end [Step step]
[statements]
Next
where count is a numeric variable used as a loop counter, start is the beginning value for count, end is the ending value, and step is the amount count is to change (defaulting to 1) for each iteration of the loop. Statements is the block of code to be executed on each iteration. The sequence of loop iterations can be either positive or negative, depending upon the step value.
The Exit For statement can be used to escape from the loop.
For Each...Next Statement
The For Each...Next statement is a variation of the For loop that can repeat a block of code for each element in an array. Its usage is
For Each entry In array
[statements]
Next [entry]
where entry is a variable used to iterate through the elements of the array, array is the name of a collection or array, and statements is a block of code to be executed on each iteration. An Exit For can be used to escape from the loop.
Function Statement
The Function statement defines the block of code that makes up a function procedure. It encompasses the name and arguments of that procedure. Its usage is
Function name [[ByVal] arg1, [ByVal] arg2, ... [ByVal] argn]
[statements]
[name = expression]
End Function
where name is the name of the function, arg1 through argn is a list of variables passed to the procedure, and statements is a block of code to be executed. The name = expression optional line returns a value to the caller of the function. The ByVal keyword indicates an argument whose value may be changed during the procedure.
An Exit Function statement can be used to escape from the function at any point.
If...Then Statement
The If...Then statement provides alternative statement execution depending upon varying conditions that may be present. Its usage is
If condition-1 Then
[statements]
[ElseIf condition-2 Then
[elifstatements]]
[Else
[elstatements]]
End If
where condition-1 and condition-2 are conditional expressions (see comparison and logical operators above), statements is a block of code executed when condition-1 is True, elifstatements is a block of code executed when condition-1 is False and condition-2 is True, and elstatements is a block of code that is executed when neither condition-1 nor condition-2 is True.
NOTE
A single line form of the If statement is available; however, its use is discouraged for readability reasons.
On Error Statement
The On Error statement identifies an error-handling routine and specifies the location of the routine within a procedure. It can also be used to disable an error-handling routine. Its usage is
On Error Resume Next
Randomize Statement
The Randomize statement sets a new seed value into the random-number generator. Its usage is
Randomize [number]
where number is a numeric expression.
ReDim Statement
The ReDim statement declares dynamic-array variables and allocates or reallocates storage space. Its usage is
ReDim [Preserve] name(subs) [,name(subs)] . . .
where Preserve indicates that the existing values in an array are to be saved when changing the size of the last dimension, name is the name of a variable, and subs are the redimensions of an array variable.
Rem Statement
The Rem statement is a nonexecutable statement and provides documentary remarks in a program. Its usages are
Rem comment
or
' comment
where comment is the text of any remarks you want to include.
Select Case Statement
Select Case executes one of several groups of statements, depending on the value of an expression. Its usage is
Select Case testexpr
[Case expr1
[statements1]]
[Case expr2
[statements2]]
.
.
.
[Case exprn
[statementsn]]
[Case Else
[elstatements]]
End Select
where testexpr is any expression; expr1, expr2, ..., and exprn are alternative values for testexpr; and statements1, statements2, ..., and statementsn are blocks of code that are executed when the value of testexpr matches the respective case expression. elstatements is a block of code that is executed when testexpr doesn't match any of the case expressions.
Set Statement
The Set statement assigns an object reference to a variable or property. Its usage is
Set objectvar = { objectexpr | Nothing}
where objectvar is the name of a variable and objectexpr is the name of an object, a variable of an object type, or a function that returns an object of an object type. If Nothing is specified, the name of the object is disassociated from objectvar.
Sub Statement
The Sub statement defines the block of code that makes up a subroutine. It encompasses the name and arguments of that routine. Its usage is
Sub name [[ByVal] arg1, [ByVal] arg2, ... [ByVal] argn]
[statements]
End Sub
where name is the name of the subroutine, arg1 through argn is a list of variables passed to the procedure, and statements is a block of code to be executed. Unlike a procedure, a subroutine cannot be used on the right side of a statement and does not return a value. The ByVal keyword indicates an argument whose value may be changed during