VB Logic发行所需的第二对眼睛

时间:2019-03-10 10:06:46

标签: arrays vb.net for-loop basic

一切正常!除了FOR LOOP可以计算出我的Results(4,2)数组中的第三列。

接口设计:

enter image description here

循环将无法运行!每条线都在循环之外运行,但是我整个下午一直在凝视。

如果您能看到我做错了的事,将不胜感激。我已经尝试了While索引

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

结束班级

1 个答案:

答案 0 :(得分:0)

我同意@MikNiller和TZHX的回答:intTaskQuantity中的变量btnCalculate_Click的值为0。