为什么变量不会上升

时间:2017-05-12 21:00:40

标签: vb.net

所以既然我已经把它变成了一个变量,即使它说i = 3,它也不会继续提问,我真的不知道还有什么要做,我就是但问题不是...... 我知道我可能会非常糟糕,但为什么直到5秒前它才起作用,现在它还没有。

Public Class Test1
Dim question(3, 5) As String
Dim i As Integer = 2
Dim correctanswear = 0
Dim a As Integer = 0
Private Sub Test1_Load()
    question(1, 0) = "2+2="
    question(1, 1) = "1"
    question(1, 2) = "2"
    question(1, 3) = "3"
    question(1, 4) = "4"
    question(2, 0) = "How old are you?"
    question(2, 1) = "12"
    question(2, 2) = "13"
    question(2, 3) = "18"
    question(2, 4) = "17"
    question(3, 0) = "7+14="
    question(3, 1) = "23"
    question(3, 2) = "21"
    question(3, 3) = "34"
    question(3, 4) = "22"
    Label1.Text = question(i - 1, 0)
    nr1.Text = question(i - 1, 1)
    nr2.Text = question(i - 1, 2)
    nr3.Text = question(i - 1, 3)
    nr4.Text = question(i - 1, 4)

End Sub

Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click
    Test1_Load()
    Button5.Hide()
    Button2.Visible = "True"
End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Hide()
    MainMenu.Show()

End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    If a > 3 Then
        MessageBox.Show("You answered " + correctanswear.ToString() + " questions correctly.")
    Else
        If i = 2 AndAlso nr4.Checked = True Then
            correctanswear += 1
            MessageBox.Show("You answered " + correctanswear.ToString() + " questions correctly.")
            i = i + 1
            MessageBox.Show(i)
        ElseIf i = 3 AndAlso nr3.Checked Then
            correctanswear += 1
            MessageBox.Show("You answered " + correctanswear.ToString() + " questions correctly.")
            i = i + 1
            MessageBox.Show(i)
        End If
        If i = 4 AndAlso nr2.Checked = True Then
            MessageBox.Show(i)
            correctanswear += 1
            MessageBox.Show("You answered " + correctanswear.ToString() + " questions correctly.")
            Button2.Hide()
            Button5.Text = "Retake the test"
            Button5.Show()

        End If
    End If
    a = a + 1

End Sub

结束班

1 个答案:

答案 0 :(得分:1)

每当用户输入正确答案时,您必须致电Test1_Load以便更新问题。

示例:

If i = 2 AndAlso nr4.Checked = True Then
    correctanswear += 1
    MessageBox.Show("You answered " + correctanswear.ToString() + " questions correctly.")
    i = i + 1
    MessageBox.Show(i)
    Test1_Load()
ElseIf i = 3 AndAlso nr3.Checked Then
    correctanswear += 1
    MessageBox.Show("You answered " + correctanswear.ToString() + " questions correctly.")
    i = i + 1
    MessageBox.Show(i)
    Test1_Load()
End If

另一方面,将问题更新为自己的函数(由Test1_Load调用并且当用户获得正确的答案时)可能值得打破问题,这样您就不必重新初始化每次测试多次问题。