我正在为我的 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