简体   繁体   English

为什么变量不增加

[英]Why won't the variable go up

So since I have put that a variable, even though it says that i=3, it doesn't go on with the questions and I really don't know what else to do, the i goes up but the questions don't.. I know I may be very bad at this but why untill 5 seconds ago it worked, now it doesn't. 因此,由于我已经输入了一个变量,即使它说i = 3,它也不会继续存在问题,而且我真的不知道该怎么做,所以i会增加,但问题不会。我知道我可能对此很不好,但是为什么直到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

End Class 末级

Whenever a user enters a correct answer you must call Test1_Load so that the question updates. 每当用户输入正确答案时,您都必须致电Test1_Load以便更新问题。

Example: 例:

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

On another note, it would probably be worth breaking the question updating code out into its own function (called by Test1_Load and when user gets a correct answer) so that you don't have to re-initialize the array of questions multiple times per test. 另一方面,可能值得将问题更新代码分解成自己的功能(由Test1_Load调用,并在用户获得正确答案时调用),这样您不必每次测试都多次重新初始化问题数组。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM