Arrays
Arrays are a single programming variable that have multiple compartments. It is like opening a single draw that has been divided into numerous compartments to store various items.
Sub ArrayNumber1()
'An array is a single programming variable with multiple "compartments".
'Each compartment can hold a value.
Dim myArray(4) As Integer 'Sets the array 'compartment' size to 4.
myArray(0) = 7 ' Starts off at compartment 0 by default.
myArray(1) = 4
myArray(2) = 8
myArray(3) = 2
MsgBox (myArray(0)) 'Gives 7
MsgBox (myArray(1)) 'Gives 4
MsgBox (myArray(2)) 'Gives 8
MsgBox (myArray(3)) 'Gives 2
End Sub
Sub ArrayNumber2()
'An array is a single programming variable with multiple "compartments".
'Each compartment can hold a value.
Dim myArray(1 To 4) As Integer 'Sets an array from 1 to 4
myArray(1) = 7
myArray(2) = 4
myArray(3) = 8
myArray(4) = 2
MsgBox (myArray(1)) 'Gives 7
MsgBox (myArray(2)) 'Gives 4
MsgBox (myArray(3)) 'Gives 8
MsgBox (myArray(4)) 'Gives 2
End Sub
Sub ArrayNumber3()
'An array is a single programming variable with multiple "compartments".
'Each compartment can hold a value.
Dim myArray() As Variant 'Allows the computer to set the date type/ size
myArray = Array(7, 4, 8, 2) ' Bulk entry of information into the array.
MsgBox (myArray(0)) 'Gives 7
MsgBox (myArray(1)) 'Gives 4
MsgBox (myArray(2)) 'Gives 8
MsgBox (myArray(3)) 'Gives 2
End Sub
Sub ArrayColor()
'An array is a single programming variable with multiple "compartments".
'Each compartment can hold a value.
Dim ColorArray() As Variant 'Allows any data type/ size to be put into the array
ColorArray = Array("blue", "red", "green", "gold")
MsgBox (ColorArray(0)) 'Gives blue
MsgBox (ColorArray(1)) 'Gives red
MsgBox (ColorArray(2)) 'Gives green
MsgBox (ColorArray(3)) 'Gives gold
End Sub