The document explains what arrays are and how they work in VB. It states that arrays allow you to store multiple values in a single variable by using compartments indexed from 0. It demonstrates declaring and populating a string array with names, then accessing each element by index and printing it to the console using a While loop to iterate through the array.
2. One Variable Can Only Hold One
Thing
Im holding
the name
DAVE
Name
3. One Variable Can Only Hold One
Thing
DONT TRY
Im holding AND PUT
the name ANOTHER
DAVE NAME IN
Name ME!
4. An Array is Different kind of Variable
Im holding Im holding Im holding
the name the name the name
DAVE ADAM CLEM
0 1 2
Name
5. An Array is Different kind of Variable
An array is a set of values that are logically related to each other,
such as the number of students in each grade in a grammar
school.
0 1 2
Name
6. An Array is Different kind of Variable
An array is like many buckets stuck together
0 1 2
Name
7. An Array is Different kind of Variable
An Array has many compartments to hold data
The array below has 3 compartments. It can hold 3 pieces
of data
0 1 2
Name
8. An Array is Different
Each compartment is labelled
The labelling starts from 0
Index 0 Index 1 Index 2
0 1 2
Name
9. An Array is Different
You can access different parts of the array by referencing
the correct index number
Index 0 Index 1 Index 2
0 1 2
Name
10. Arrays In VB
Declaring the
Declaring the Declaring the data type of the
Array size of the Array Array, in this
case a String
Dim names(3) As String
names(0) = "DAVE"
Declaring the
contents of the names(1) = "ADAM"
Array
names(2) = "CLEM"
11. Arrays In VB
Dim names(3) As String
names(0) = "DAVE"
names(1) = "ADAM"
names(2) = "CLEM"
Console.WriteLine(names(0))
Console.WriteLine(names(1))
Console.WriteLine(names(2))
Writing the
contents of the
Console.ReadLine()
array to the
console.
12. Arrays In VB
Dim names(3) As String
names(0) = "DAVE"
names(1) = "ADAM"
names(2) = "CLEM"
Console.WriteLine(names(0))
Console.WriteLine(names(1))
Console.WriteLine(names(2))
Console.ReadLine()
Erasing the
contents of the
Erase names
Array
13. Arrays and WHILE
Module Module1
The while loop will
Sub Main() look at every
Dim names(3) As String
compartment of
names(0) = "DAVE" the names array
names(1) = "ADAM"
names(2) = "CLEM"
Dim i As Integer = 0
While i < names.Length - 1
Console.WriteLine(names(i))
i = i + 1
End While
Console.ReadLine()
End Sub
14. Arrays and WHILE
Module Module1
Sub Main()
Dim names(3) As String
names(0) = "DAVE"
names(1) = "ADAM"
names(2) = "CLEM"
Dim i As Integer = 0
While i < names.Length
Console.WriteLine(names(i))
i = i + 1
End While
Console.ReadLine()
End Sub