Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q7012 How Do I Use Arrays?

You are here: irt.org | FAQ | VBScript | Q7012 [ previous next ]

Arrays may either be static or dynamic. A static array has its dimensions pre-defined and may not be re-sized, whereas a dynamic array does not have a pre-defined number of dimensions and must be resized to store any data. To define any of the two arrays first use either the Dim, Public, or Private statments as you would with a normal variable. Then, to define a one-dimensional static array with three elements, you could go:

Dim myArray(2)

To assign values to each element go:

myArray(0) = 34
myArray(1) = 45
myArray(2) = 12

You may have also defined the above array by using the Array( ) function like so:

Dim A
A = Array(34,45,12)

Arrays may be defined with as many as 60 dimensions. Array dimensions are separated by commas. For example to define a three-dimensional array you could go:

Public myArray(4, 7, 9)

Where the first dimension has 5 elements, the second has 8 elements, and the last has 10 elements.

Dynamic arrays have no dimensions when they are defined and cannot contain data until they are re-dimensioned. To define a dynamic array simply go:

Dim myArray( )

©2018 Martin Webb