by Dinesh Thakur Category: Array

A standard structure for storing data in any programming language is an array. Whereas individual variables can hold single entities, such as a number, date, or string, arrays can hold sets of related data.

 

An array has a name, as does a variable, and the values stored in it can be accessed by an index.

 

Declaring Arrays : Single Dimensional Array—Used to store long sequences of one dimensional data. Unlike simple variables, arrays must be declared with the Dim statement followed by the name of the array and the maximum number of elements it can hold in parantheses,

e.g. Dim Sal(15)

Multidimensional Array—To store the data in a tabular or matrix form, we need two dimensional array and to store sequences of multidimensional data we need multidimensional array.

In two dimensional array, first index represent the row and the second represents the column.

e.g. Dim Board(5,5) As Integer

 

Dynamic Arrays : Sometimes you may not know how large to make an array. Instead of making it large enough to hold the maximum number of data, you can declare a dynamic array. The size of a dynamic array can vary during the course of the program.

To create a dynamic array, declare it as usual with the Dim statement, but don’t specify its dimensions :

 

Dim DynArray()

Later in the program, when you know how many elements you want to store in the array, use the ReDim statement to redimension the array, this time with its actual size.

 

ReDim DynArr(UserCount)

Here UserCount is a user-entered value.

The ReDim statement can only appear in a procedure.

 



About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.SC (Computer Science), MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.