Все работает! За исключением FOR LOOP, который вычисляет третий столбец в моем массиве Results (4,2).
Дизайн интерфейса:
Цикл не запустится! Каждая строка работает вне цикла, но я смотрел на это весь день.
Буду очень признателен, если вы поймете, что я сделал неправильно. Я пробовал Пока индекс
Imports System.Xml
Калькулятор общественного класса
Dim strStudentName As String
Dim strTaskName(4) As String
Dim dblTaskWeighting(4) As Double
Dim Results(4, 2) As Double
Dim intTaskQuantity As Integer
Dim dblWeightedResult As Double
Dim dblWeightedItem As Double
Dim strLetterGrade As String
Private Sub btnYear11_Click_1(sender As Object, e As EventArgs) Handles btnYear11.Click
Dim xr As XmlReader = XmlReader.Create("Year11.xml")
Do While xr.Read()
If xr.NodeType = XmlNodeType.Element AndAlso xr.Name = "Name" Then
lbxSelectedClass.Items.Add(xr.ReadElementString)
End If
Loop
End Sub
Private Sub btnYear10_Click(sender As Object, e As EventArgs) Handles btnYear10.Click
Dim xr As XmlReader = XmlReader.Create("Year10.xml")
Do While xr.Read()
If xr.NodeType = XmlNodeType.Element AndAlso xr.Name = "Name" Then
lbxSelectedClass.Items.Add(xr.ReadElementString)
End If
Loop
End Sub
Private Sub btnClearClass_Click(sender As Object, e As EventArgs)
lbxSelectedClass.Items.RemoveAt(lbxSelectedClass.SelectedIndex.ToString())
End Sub
Private Sub btnEnter_Click(sender As Object, e As EventArgs) Handles btnEnter.Click
strStudentName = lbxSelectedClass.SelectedItem
Dim intTaskQuantity As Integer = Val(InputBox("How many assessment tasks did " & strStudentName & " complete?"))
If intTaskQuantity = 4 Then
lblTask5.Visible = False
txtTask5Result.Visible = False
txtTask5Total.Visible = False
lblWeighting5.Visible = False
ElseIf intTaskQuantity = 3 Then
lblTask5.Visible = False
txtTask5Result.Visible = False
txtTask5Total.Visible = False
lblWeighting5.Visible = False
lblTask4.Visible = False
txtTask4Result.Visible = False
txtTask4Total.Visible = False
lblWeighting4.Visible = False
ElseIf intTaskQuantity = 2 Then
lblTask5.Visible = False
txtTask5Result.Visible = False
txtTask5Total.Visible = False
lblWeighting5.Visible = False
lblTask4.Visible = False
txtTask4Result.Visible = False
txtTask4Total.Visible = False
lblWeighting4.Visible = False
lblTask3.Visible = False
txtTask3Result.Visible = False
txtTask3Total.Visible = False
lblWeighting3.Visible = False
ElseIf intTaskQuantity = 2 Then
lblTask5.Visible = False
txtTask5Result.Visible = False
txtTask5Total.Visible = False
lblWeighting5.Visible = False
lblTask4.Visible = False
txtTask4Result.Visible = False
txtTask4Total.Visible = False
lblWeighting4.Visible = False
lblTask3.Visible = False
txtTask3Result.Visible = False
txtTask3Total.Visible = False
lblWeighting3.Visible = False
lblTask2.Visible = False
txtTask2Result.Visible = False
txtTask2Total.Visible = False
lblWeighting2.Visible = False
End If
For i = 0 To (intTaskQuantity - 1)
strTaskName(i) = InputBox("What the name of Task number " & i + 1 & " ?")
dblTaskWeighting(i) = Val(InputBox("What the weighting for that task?"))
lblTask1.Text = strTaskName(0)
lblTask2.Text = strTaskName(1)
lblTask3.Text = strTaskName(2)
lblTask4.Text = strTaskName(3)
lblTask5.Text = strTaskName(4)
lblWeighting1.Text = ((dblTaskWeighting(0) * 100) & " % ")
lblWeighting2.Text = ((dblTaskWeighting(1) * 100) & " % ")
lblWeighting3.Text = ((dblTaskWeighting(2) * 100) & " % ")
lblWeighting4.Text = ((dblTaskWeighting(3) * 100) & " % ")
lblWeighting5.Text = ((dblTaskWeighting(4) * 100) & " % ")
Next
End Sub
Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click
Results(0, 0) = Val(txtTask1Result.Text)
Results(0, 1) = Val(txtTask1Total.Text)
Results(1, 0) = Val(txtTask2Result.Text)
Results(1, 1) = Val(txtTask2Total.Text)
Results(2, 0) = Val(txtTask3Result.Text)
Results(2, 1) = Val(txtTask3Total.Text)
Results(3, 0) = Val(txtTask4Result.Text)
Results(3, 1) = Val(txtTask4Total.Text)
Results(4, 0) = Val(txtTask5Result.Text)
Results(4, 1) = Val(txtTask5Total.Text)
For index As Integer = 0 To intTaskQuantity - 1
Results(index, 2) = ((Results(index, 0) / Results(index, 1)) * 100)
lbxResults.Items.Add(strTaskName(index) & " : " & Results(index, 2) & "%")
dblWeightedItem = (Results(index, 2) * dblTaskWeighting(index))
dblWeightedResult = dblWeightedResult + dblWeightedItem
Next
If dblWeightedResult > 85 Then
strLetterGrade = "A"
ElseIf dblWeightedResult <= 85 And dblWeightedResult > 75 Then
strLetterGrade = "B"
ElseIf dblWeightedResult <= 75 And dblWeightedResult > 45 Then
strLetterGrade = "C"
ElseIf dblWeightedResult <= 45 And dblWeightedResult > 45 Then
strLetterGrade = "D"
ElseIf dblWeightedResult <= 45 And dblWeightedResult > 35 Then
strLetterGrade = "E"
ElseIf dblWeightedResult < 35 Then
strLetterGrade = "F"
Else
strLetterGrade = "Not Graded"
End If
MsgBox(strStudentName & " has been awarded the final grade of " & strLetterGrade)
End Sub
Конечный класс