Private Sub btnGtGrades_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGtGrades.Click
Dim my As IO.StreamReader
Dim fmtStr As String = "{0,11}{1,4} {2,8} {3,6} {4,6}"
Dim strStudent, Start As String, strLetterGrade As String
Dim Grade1, Grade2, total As Double
Dim varEveryonesGrade As Double
Dim varAverage As Double
Dim sum As Integer
varAverage = 0
sum = 0
If IO.File.Exists("A:\grades.txt") Then
my = IO.File.OpenText("A:\grades.txt")
Do While my.Peek <> -1
Start = my.ReadLine
strStudent = Start.Substring(0, 11)
Grade1 = Start.Substring(12, 4)
Grade2 = Start.Substring(16, 4)
varAverage = Math.Round((Grade1 + Grade2) / 2, 0)
varEveryonesGrade += varAverage
sum += 1
varEveryonesGrade = Math.Round(varEveryonesGrade / sum)
txtDsplyClsAvr.Text = "The class average is " & CStr(varEveryonesGrade)
Select Case varAverage
Case Is >= 90
strLetterGrade = "A"
Case Is >= 80
strLetterGrade = "B"
Case Is >= 70
strLetterGrade = "C"
Case Is >= 60
strLetterGrade = "D"
Case Is >= 50
strLetterGrade = "F"
End Select
lstGtGrds.Items.Add(String.Format(fmtStr, strStudent, Grade1, Grade2, varAverage, strLetterGrade))
Loop
Else
MsgBox("Try putting in the disk that has grades.txt on it!, , Missing Disk")
End If
my.Close()
End Sub
End Class