Creating and Accessing Arrays
A variable (or simple variable) is a name to which Visual Basic can assign a single value. An
array
variable is a collection of simple variables of the same type to which Visual Basic can efficiently
assign
a list of values.
Consider the following situation: Suppose that you want to evaluate the exam grades for 30
students.
Not only do you want to compute the average score, but you also want to display the names of
the
students whose scores are above average. You might place the 30 pairs of student names and
scores in a
text file and run the program outlined:
Private Sub btnDisplay_Click(...) Handles [Link]
Dim student1 As String, score1 As Double
Dim student2 As String, score2 As Double
Dim student3 As String, score3 As Double
.
.
Dim student30 As String, score30 As Double
'Analyze exam grades
Dim sr As [Link] = [Link]("[Link]")
student1 = [Link]
score1 = CDbl([Link])
student2 = [Link]
score2 = CDbl([Link])
student30 = [Link]
score30 = CDbl([Link])
[Link]()
'Compute the average grade
'Display names of above average students
End sub
For i As Integer = 1 To 30
studenti = [Link]
scorei = CDbl([Link])
Next
Next
End Sub
End Module