You are on page 1of 2

Public Class Form1

'implicit parallel array declaration


Dim studID() As String = {"035001", "035002", "035003", "036001", "036002",
"036003"}
Dim totalScore() As Integer = {75, 66, 58, 93, 78, 45}
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub btnResults_Click(sender As Object, e As EventArgs) Handles btnRe
sults.Click
Dim index As Integer
Dim s As String = "TP"
'display headers
lstDisplay.Items.Add("Student ID" & ControlChars.Tab & "Scores")
'display all the content of the array
For index = 0 To studID.GetUpperBound(0)
lstDisplay.Items.Add(s.Insert(2, studID(index)) & ControlChars.Tab &
totalScore(index))
Next
TextBox3.Text = FindHighest().ToString
TextBox4.Text = FindAverage().ToString("n")
TextBox5.Text = FindLowest().ToString
End Sub
Function FindHighest() As Integer
Dim max As Integer = totalScore(totalScore.GetUpperBound(0))
Dim index As Integer
For index = 0 To totalScore.GetUpperBound(0)
If (totalScore(index) > max) Then
max = totalScore(index)
End If
Next
Return max
End Function
Function FindAverage() As Single
Dim i As Integer
Dim total As Integer
For Each i In totalScore
total += i
Next
Return total / totalScore.Length
End Function
Function FindLowest() As Integer
Dim min As Integer = totalScore(totalScore.GetLowerBound(0))
Dim index As Integer
For index = 0 To totalScore.GetUpperBound(0)
If (totalScore(index) < min) Then
min = totalScore(index)
End If
Next
Return min
End Function
Private Sub btnSearch_Click(sender As Object, e As EventArgs) Handles btnSearch.
Click
Dim search As String
Dim getIndex As Integer
search = txtSearch.Text

For Each i As String In studID


If (i.Equals(search)) Then
getIndex = Array.IndexOf(studID, i)
Exit For
End If
Next
'display the found item
lblScore.Text = totalScore(getIndex)
End Sub
End Class

You might also like