Avis Junior Poster

Joined: 07 Oct 2003 Posts: 510 Location: India
|
Posted: Oct 8th, 2003 05:25 AM Post subject: Tutorial on Arrays |
|
|
Arrays are simple. It can easily be described as a variable which has a bunch
of little variables inside of them, each sub variable having a serial number.
| Code: | 'Syntax:
Myarray(Insert any number here) = insert any value here
'Example:
Dim MyArray() As Variant 'Makes the array exist.
ReDim MyArray(1 To 3) 'States that there are 3 subvariables
MyArray(1) = "A" 'Sets subvariable '1' to "A"
MyArray(2) = "B" 'Sets subvariable '2' to "B"
MyArray(3) = "C" 'Sets subvariable '3' to "C"
MsgBox MyArray(1) & MyArray(2) & MyArray(3)
'Displays all three subvariables in one MessageBox |
But know that you may use variables to define the subvariable you wish to
change or retrieve
| Code: | Dim MyArray() As Variant
ReDim MyArray(1 To 3)
For i = 1 To 3
MyArray(i) = 5 * i
Next
For i = 1 To 3
MsgBox MyArray(i)
Next |
But you are also capable of having an Array with more than one
"subvariable" ID number. These are called Multidimensional Arrays.
| Code: | 'Syntax:
Dim TimesTable() As Long
ReDim TimesTable(insert number here, insert another number here)
'Example:
Dim TimesTable() As Long
ReDim TimesTable(1 To 100, 1 To 100)
For x = 1 To 100
For y = 1 To 100
TimesTable(x, y) = x * y
Next y
Next x
MsgBox TimesTable(InputBox("Give me a number between 1 and 100."), InputBox("Give me another number between 1 and 100.")) |
|
|