Monday, April 26, 2010

What is Array in VB scripting

First of all let us understand what is an array in VB Scripting. How are arrays used in VB Scripting. What is the purpose of array in VB Script. Is there any difference between an array and a variable since both store values? What does an array do and how does an array store values.


Array is a matrix of data. The difference between a variable and an array is that a variable holds a single value while an array holds multiple values. Array can be Static and Dynamic.

An array is said to be static if the upper limit of the array is known or defined. If the upper limit is not defined and the value is fetched from some other place or a user input it is known as Dynamic array.

Arrays should always be declared with a Dim Statement. In VB script a Dynamic array is classified as Homogenous and Heterogeneous. A Homogenous array hold the same type of data while an heterogeneous array is a mix of different data types.

Generally an array in VB Script can be of 60 dimensions.

Syntax of a Single Dimensional Array

Dim [Array name] (index)

It is to be noted that in an array the index begins with zero.

Syntax of a two dimensional array

Dim [Array name] (column id, row id)

Example of a two dimensional array

Dim arrphonelist (2,3)

Arrphonelist is the name of the array while 2 is the column id and is also known as 1st dimension and 3 is the row id and is also known as 2nd dimension.

To get the row count of an array we write like this

Row_count = ubound(arrphonelist, 2)

For column count it is like this even though we predefine the number of rows as a best practice but still to have an idea we write like this

column_count = ubound(arrphonelist, 1)

In an array always the columns are fixed and only rows are manipulated.

1 comment:

Unknown said...

thanks alot for the blog..

i have one doubt abiut 2D array.. ur blog says
Dim [Array name] (column id, row id)

but microsoft's msdn says the following..

"In a two-dimensional array, the first number is always the number of rows; the second number is the number of columns. "

Post a Comment