我的目标是生成一个随机问题(+,*或 - )和一个答案,当我点击一个我已经能够做到的按钮时。问题是,当我生成它时,它会返回一个问题(标签)和一个答案(MessageBox),但是当我单击确定的消息框时,会直接询问另一个问题,一旦我忽略该消息框,它会停止询问。我的随机测验生成器返回两个问题
Private Sub Generate()
'This is my first random value'
Dim rnd1 As New Random
'This is my Second random Value'
Dim rnd2 As New Random
'This value will decide weather it is a +, * or -'
Dim rnd3 As New Random
'Declaring first value as an integer'
Dim Val1 As Integer
'Declaring second value as an integer'
Dim Val2 As Integer
'This will calculate the answer'
Dim Ans As Double
'This is what I will reference to to display the question'
Dim question As String
'If the random value is equal to 1, the question is an addition'
If (rnd3.Next(1, 3) = 1) Then
Val1 = rnd1.Next(1, 20)
Val2 = rnd2.Next(1, 25)
Ans = Val1 + Val2
question = Val1.ToString() + "+ " + Val2.ToString()
lbl_ques.Text = question
MessageBox.Show("Answer = " + Ans.ToString())
Val1 = 0
Val2 = 0
Ans = 0
question = ""
End If
'If the random value is equal to 2, the question is a multiplication'
If (rnd3.Next(1, 3) = 2) Then
Val1 = rnd1.Next(1, 10)
Val2 = rnd2.Next(1, 17)
Ans = Val1 * Val2
question = Val1.ToString() + "* " + Val2.ToString()
lbl_ques.Text = question
MessageBox.Show("Answer = " + Ans.ToString())
Val1 = 0
Val2 = 0
Ans = 0
question = ""
End If
'If the random value is equal to 3, the question is a subtraction'
If (rnd3.Next(1, 3) = 3) Then
Val1 = rnd1.Next(1, 50)
Val2 = rnd2.Next(1, 43)
Ans = Val1 - Val2
question = Val1.ToString() + "- " + Val2.ToString()
lbl_ques.Text = question
MessageBox.Show("Answer = " + Ans.ToString())
Val1 = 0
Val2 = 0
Ans = 0
question = ""
End If
End Sub
我怎样才能阻止它直接产生另一个问题和答案?由于
PS如果你想知道为什么我用VB这是因为它的一个学校项目,必须是在VB:/我通常使用C#
当它会工作,将其发送到http://codereview.stackexchange.com/你会得到一些关于如何抛光你的代码的好建议。 – 2014-12-02 16:11:24