私の目標はこれを行うことです: ファイルから配列にデータを読み取り、リスト ボックスをロードし、各学生の平均を計算し、文字の成績を決定し、クラスの平均を計算します。
私の宣言された変数(グローバル):
Dim project, midterm, hw1, hw2, final, count, average As Integer
Dim letterGrade, lastName, firstName As String
Dim classAverage As Double
私のコード:
Dim array1 As String() = New String(6) {}
Dim streamreader1 As StreamReader = File.OpenText("grades.csv")
count = 0
classAverage = 0
Do While (streamreader1.Peek() <> -1)
array1 = Strings.Split(streamreader1.ReadLine(), ",", -1)
firstName(count) = array1(0)
lastName(count) = array1(1)
lstNames.Items.Add(lastName(count) & ", " & firstName(count))
hw1(count) = Convert.ToString(array1(2))
hw2(count) = Convert.ToString(array1(3))
project(count) = Convert.ToString(array1(4))
midterm(count) = Convert.ToString(array1(5))
final(count) = Convert.ToString(array1(6))
average(count) = Math.Round(Math.Truncate((((((hw1(count) + hw2(count)) + (2 * project(count))) + (4 * (midterm(count) + final(count)))) / 12) + 0.5)))
classAverage = (classAverage + ((((hw1(count) + hw2(count)) + (2 * project(count))) + (4 * (midterm(count) + final(count)))) / 12))
Dim num1 As Integer = average(count)
If (num1 >= 93) Then
letterGrade(count) = "A"
ElseIf (num1 >= 90) Then
letterGrade(count) = "A-"
ElseIf (num1 >= 87) Then
letterGrade(count) = "B+"
ElseIf (num1 >= 83) Then
letterGrade(count) = "B"
ElseIf (num1 >= 80) Then
letterGrade(count) = "B-"
ElseIf (num1 >= 77) Then
letterGrade(count) = "C+"
ElseIf (num1 >= 73) Then
letterGrade(count) = "C"
ElseIf (num1 >= 70) Then
letterGrade(count) = "C-"
ElseIf (num1 >= 67) Then
letterGrade(count) = "D+"
ElseIf (num1 >= 63) Then
letterGrade(count) = "D"
ElseIf (num1 >= 60) Then
letterGrade(count) = "D"
Else
letterGrade(count) = "E"
End If
count = (count + 1)
Loop
classAverage = (classAverage / count)
lstNames.SelectedIndex = 0
PopulateLabels(0)
streamreader1.Close()