Vb.net 我的随机测验生成器返回两个问题

Vb.net 我的随机测验生成器返回两个问题,vb.net,random,Vb.net,Random,我的目标是在我点击一个按钮时生成一个随机问题(+、*或-)和一个答案,我已经能够做到这一点。问题是,当我生成它时,它会返回一个问题(标签)和一个答案(MessageBox),但当我单击MessageBox上的ok时,它会立即询问另一个问题,一旦我关闭MessageBox,它就会停止询问 Private Sub Generate() 'This is my first random value' Dim rnd1 As New Random 'This is my Sec

我的目标是在我点击一个按钮时生成一个随机问题(+、*或-)和一个答案,我已经能够做到这一点。问题是,当我生成它时,它会返回一个问题(标签)和一个答案(MessageBox),但当我单击MessageBox上的ok时,它会立即询问另一个问题,一旦我关闭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
我怎样才能阻止它产生另一个问题和答案呢?谢谢

如果你想知道我为什么要用VB,那是因为它是为了一个学校项目,而且必须用VB:/我通常用c#

或者用

退出当前子例程的退出子例程

If ... Then

    Exit Sub
End If
or和ElseIf仅执行一个If条件

If ... Then

ElseIf ... Then

End If
或(优选地)选择案例陈述

Select Case rnd.Next(1, 3)

Case 1

Case 2

Case 3

End Select
旁注:您只需创建一个随机对象,然后调用即可。接下来,每次使用适当的值时,将其发送给您,您将获得一些关于如何完善代码的好建议。