#title RCBasic Arrays [RCBasic Doc]
#header ARRAYS


In complex programs there is often a need to be able to store large amounts of data.  It would be unreasonable to have to create a variable for each piece of data we may need to store.  This is where an array can come in handy.  Arrays are simply ways of using one variable to store multiple different values.  You can create arrays of numbers or strings.  Look at the following:
#code
Dim A[5]
#/code

The above example creates an array of numbers called A.  A can store five numbers which are retrieved using A[0] to A[4].  Notice that A[4] is the last element in the array and not A[5].  That is because the first index in the array is 0 and the array only stores 5 numbers.  To set the values in this array you could do the following:
#code
A[0] = 3
A[1] = 2
A[2] = 7
A[3] = 1
A[4] = 0
#/code

You would access and array just like you would a variable.  Look at the following:
#code
X = A[0] + A[3]     '( Based on the above example the variable X would be set to 4. )
#/code

To make a string variable you would do the same thing you do to make a number variable except you would use the $ just like you would use to make a normal string variable.  Look at the following:
#code
Dim B$[3]

B[0] = "ABC"
B[1] = "DEF"
B[2] = "I KNOW THE ALPHABET"
#/code

Arrays can have up to 3 dimensions.  Adding more dimensions to an array can make organizing data in the array easier depending on the situation.  Look at the following:
#code
Dim  X[2, 3]
Dim  Y[3, 4, 5]
#/code

The above example creates a 2 dimensional array called X which has 2 indices in its first dimension.  Its second dimension has 3 indices.  This means that each of the 2 indices in the first dimension can store 3 different values.  So X can store a total of 6 different values.  The second line creates a 3 dimensional array called Y.  Y has 3 indices in its first dimension.  Each of those 3 indices has 4 indices in its 2nd dimension.  Each of the 4 indices has 5 values it can store.  This means that Y can store a total of 60 different values.  Look at the following for an example on how to work with these multi-dimensional arrays:
#code
X[0, 2] = 5      '(This line sets the 3rd value in the first index to 5.  Remember that the first index is always 0 so the 3rd index will be 2.)

Y[1, 2, 3] = 6   '(This line sets the 4th value of the 3rd index in the 2nd index in the array to 6. That was a mouth full. ) 
#/code
