使用随机VB输出错误

时间:2013-05-06 20:33:51

标签: vb.net visual-studio-2010

我正在为我的vba类编写一个程序,它几乎已经完成,但我遇到了一个小问题。该程序应该询问随机乘法问题,然后用户点击提交以检查天气是对还是错。一切正常,但第一个问题的答案是所有这些问题的答案,即使用户下一个问题下一个问题也是如此。例如,第一个问题可能是6 * 3,用户输入21,它会说正确。下一个问题将出现说3 * 2.如果用户输入6则表示错误,但如果再次输入21则表示正确。我确定我错过了一些非常简单的东西,但它让我疯狂,我对此很陌生。非常感谢任何帮助!!如果有任何疑问,请抱歉。

Public Class MultiplicationTeacherForm
    Dim randomObject As New Random
    Dim one As Integer = randomObject.Next(1, 10)
    Dim two As Integer = randomObject.Next(1, 10)

Private Sub nextButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles nextButton.Click

    Dim one As Integer = randomObject.Next(1, 10)
    Dim two As Integer = randomObject.Next(1, 10)
    question.Text = ("How much is " & one & " times " & two)

End Sub

Private Sub submitButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles submit.Click

    Dim three As Integer = randomObject.Next(1, 3)
    Dim ans As Integer = one * two
    Dim correct As String = answer.Text
    Dim x As Integer = Convert.ToInt16(correct)

    If (three = 1) And (ans = x) Then
        response.Text = "Very Good!"
    ElseIf (three = 2) And (ans = x) Then
        response.Text = "Excellent!"
    ElseIf (three = 3) And (ans = x) Then
        response.Text = "Great Job!"
    Else
        response.Text = "No, Please try again."
    End If
End Sub


Private Sub MultiplicationTeacherForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    question.Text = ("How much is " & one & " times " & two)
End Sub

1 个答案:

答案 0 :(得分:2)

您的nextButton_Click未更新表单的onetwo变量,而是创建隐藏表单的新本地文件。只是做:

one = randomObject.Next(1, 10)
two = randomObject.Next(1, 10)

而不是你已经拥有的前两行。