我试图将等式的右侧作为标签的文本,但它不适合我。
num1
和num2
是随机数。
Private Sub Start_Click(sender As Object, e As EventArgs) Handles
Start.Click
Dim max
Dim num1
Dim num2
max = InputBox("Geef een maximumwaarde in. ")
Dim rnd As New Random
num1 = rnd.Next(0, max)
num2 = rnd.Next(0, max)
If num1 < (max / 2) Or num2 < (max / 2) Then
LOpgave.Text = (Str(num1) + Str(num2))
End If
If num1 > num2 And (num1 - num2) > 0 Then
LOpgave.Text = (Str(num1) - Str(num2))
End If
If (num1 * num2) > 0 And (num1 * num2) < max Then
LOpgave.Text = (Str(num1) * Str(num2))
End If
If num1 > num2 Then
LOpgave.Text = (Str(num1) / Str(num2))
End If
期望的输出: 如果num1 = 9且num2 = 3且max = 60 输出将是: '9 + 3' 要么 '9/3' 等等 使用我目前拥有的代码,它只是解决方程式。
答案 0 :(得分:0)
尝试以下方法:
Private Sub Start_Click(sender As Object, e As EventArgs) Handles Start.Click
Dim max
Dim num1
Dim num2
max = InputBox("Geef een maximumwaarde in. ")
Dim rnd As New Random
num1 = rnd.Next(0, max)
num2 = rnd.Next(0, max)
If num1 < (max / 2) Or num2 < (max / 2) Then
LOpgave.Text = (Str(num1) & " + " & Str(num2) & " = " & num1 + num2)
End If
If num1 > num2 And (num1 - num2) > 0 Then
LOpgave.Text = (Str(num1) & " - " & Str(num2) & " = " & num1 - num2)
End If
If (num1 * num2) > 0 And (num1 * num2) < max Then
LOpgave.Text = (Str(num1) & " * " & Str(num2) & " = " & num1 * num2)
End If
If num1 > num2 Then
LOpgave.Text = (Str(num1) & " / " & Str(num2) & " = " & num1 / num2)
End If
End Sub
正如对OP的评论中所提到的,&
运算符将连接字符串。我无法保证代码的其余部分,但打印似乎与此版本一起使用。
答案 1 :(得分:0)
谢谢!这就是我需要的答案!!!
Private Sub Start_Click(sender As Object, e As EventArgs) Handles Start.Click
Dim max
Dim num1
Dim num2
max = InputBox("Geef een maximumwaarde in. ")
Dim rnd As New Random
num1 = rnd.Next(0, max)
num2 = rnd.Next(0, max)
If num1 < (max / 2) Or num2 < (max / 2) Then
LOpgave.Text = (Str(num1) & " + " & Str(num2) & " = " & num1 + num2)
End If
If num1 > num2 And (num1 - num2) > 0 Then
LOpgave.Text = (Str(num1) & " - " & Str(num2) & " = " & num1 - num2)
End If
If (num1 * num2) > 0 And (num1 * num2) < max Then
LOpgave.Text = (Str(num1) & " * " & Str(num2) & " = " & num1 * num2)
End If
If num1 > num2 Then
LOpgave.Text = (Str(num1) & " / " & Str(num2) & " = " & num1 / num2)
End If
End Sub