vbscript – Array

FUNCTION:  Array( )


Implemented in version 2.0

Array(List)

The Array function is used to create a static one-dimension array. You cannot declare a dynamic array using the Array function.

Note that the first element in an array is always labeled zero, for example,
myarray(0).

The List argument is a listing of values that will become the elements of the array.

Code:
<% myarray = array(« A », « B », « C », « D ») %>
<% =myarray(0) %>
<% =myarray(1) %>
<% =myarray(2) %>
<% =myarray(3) %>

Output:
A
B
C
D

Code:
<% myarray = array(111, 222, 333, 444, 555) %>
<% =myarray(0) %>
<% =myarray(1) %>
<% =myarray(2) %>
<% =myarray(3) %>
<% =myarray(4) %>

Output:
111
222
333
444
555

A dynamic array is declared using the Dim and the ReDim statements. First, you use the Dim statement to declare the dynamic array by using empty parenthesis. Then, at a later point in your program, you use the ReDim statement to declare the number of elements. In fact, you can re-declare a dynamic array as many times as you desire.

Code:
<%
Dim SomeArray()

ReDim SomeArray(22)

ReDim SomeArray(500)
%>

Arrays can have up to sixty dimensions. If you wish to create a multiple-dimension array, you need to declare it using the Dim statement. For example, the following code creates a three dimensional array. The first dimension has 23 elements, the second dimension has 15 elements and the third dimension has 201 elements. Therefore, there are a total of 23x15x201 = 69345 elements in this array.

The number of dimensions that you can create is limited by the available memory. If you exceed the available memory while declaring an array, you will get an error message.

Code:
<% Dim ThreeDimensionArray(22, 14, 200) %>

vbscript – And

OPERATOR:  And


Implemented in version 1.0

And

The And operator is used to perform a logical conjunction on two expressions, where the expressions are Null, or are of Boolean subtype and have a value of True orFalse.

The And operator can also be used a « bitwise operator » to make a bit-by-bit comparison of two integers. If both bits in the comparison are 1, then a 1 is returned. Otherwise, a 0 is returned.

When using the And to compare Boolean expressions, the order of the expressions is not important.

Code:
<% =True And True %>
<% =True And False %>
<% =False And True %>
<% =False And False %>
<% =True And Null %>
<% =Null And True %>
<% =False And Null %>
<% =Null And False %>
<% =Null And Null %>

Output:
True
False
False
False
(Null output)
(Null output)
False
False
(Null output)

Code:
<% anyexpression = True %>
<% someexpression = False %>
<% =anyexpression And someexpression %>

Output:
False

In this example, the And performs a bitwise comparison on the 1 (in binary 001) and the 2 (in binary 010), and returns a 0 (in binary 000).

Code:
<%
Expression1 = 1
Expression2 = 2
Result = Expression1 And Expression2
Response.Write « Result =  » & Result
%>

Output:
Result = 0

vbscript-equal

OPERATOR:   =


Implemented in version 1.0

 =

The operator is used to assign a value to a variable, or to compare strings and numbers, or to print out the value of a variable.

When used for assignment, a single variable on the left side of the = operator is given the value determined by one or more variables and/or expressions on the right side.

Code:
<% mynumber = 5.0 + 7.9*(444.999 / 456.9) %>
<% mystring = « The moon is 2160 miles in diameter. » %>
<% myvar = xxx + yyy + zzz %>
<% myarray(40) = 12345 %>

The = operator can also compare two strings or two numbers and see if they are the same. For strings, the comparison is case sensitive.

Code:
<% = »Apple »= »Apple » %>
<% = »aPPle »= »ApplE » %>

<% =123=123 %>
<% =5.67=98.7 %>

Output:
True
False

True
False

When the = operator is used to print out the value of a variable, the statement must be enclosed by its own set of <% %>. There can blank spaces between the = operator and the variable.

Code:
<% myfish = « Neon tetra » %>
<% =myfish %>
<% = myfish %>

Output:
Neon tetra
Neon tetra

vbscript-plus

OPERATOR: +


Implemented in version 1.0

+

The + operator has two uses. It is used to add numbers together. It also may be used to concatenate (combine) strings together.

Note it is usually recommended that only the & operator be used for string concatenation.

Addition:

Code:
<% total = 5.678 + 0.234 + 23.1 %>

Output:
29.012

Concatenation:

Code:
<% cheese= » is made of blue cheese. » %>
<% sentence= »The moon » + cheese +  » Mice like blue cheese. » %>

Output:
The moon is made of blue cheese. Mice like blue cheese.