Home / Visual Basic Tutorial / Declaration Of Array

Declaration Of Array

Syntax:
Dim arrayname(number) as Datatype

Example:
Dim total(10) as integer

Here total is name of array ,10 is no of elements in the array & integer is the data type.Number 10 included in the parenthesis is the upper limit of the array.

The above declaration creates an array with index numbers ranging from 0 to 9.

If you want to specify lower limit ,then the parenthesis should include both the lower and upper limit along with the ‘To’ keyword.

An example is shown below

Dim num(1 To 5) As integer
In above statement, an array of 5 element is declared but with the index numbers ranging from 1 to 5.

Mainly Visual Basic supports 2 types of Array:

Fixed-Size array:
The size of array always remains the same.

Dynamic array:
The size of array can be changed at run time.