Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 为什么变量不会上升_Vb.net - Fatal编程技术网

Vb.net 为什么变量不会上升

Vb.net 为什么变量不会上升,vb.net,Vb.net,所以,既然我把它作为一个变量,即使它说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)

所以,既然我把它作为一个变量,即使它说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

每当用户输入正确答案时,必须调用Test1\u 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\u Load调用的函数,这样您就不必在每次测试中多次重新初始化问题数组。

请解释您希望在标签中看到什么以及您看到什么。问题2+2=?尽管如此,消息框显示i=3,问题应该改变,它被卡住了。