-2
  Randomize()
        Dim value As Integer = CInt(Int((10 * Rnd()) + 1))
        num1 = value
        num2 = value

        If TextBox2.Text = (num1 * num2) Then
            TextBox3.Text = " correct ! "
        Else
            TextBox3.Text = "sorry, try again"

        End If

我无法让 Num1/num2 等于数字 1-10。

我将如何对其进行编码以使 num1 和 num2 等于数字 1-10?

4

3 回答 3

1
Randomize()
        Dim value As Integer = CInt(Int((10 * Rnd()) + 1))
        Dim num1 As Integer = value
        value = CInt(Int((10 * Rnd()) + 1))
        Dim num2 As Integer = value

这会起作用

于 2013-06-11T13:00:50.170 回答
1

这说明了如何使用 .Net 的 Random 类。使用它代替 Rnd。

Dim prng As New Random

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
    Dim value As Integer = prng.Next(1, 11) '1-10 upper range is exclusive
    Dim num1 As Integer = prng.Next(1, 11) '1-10 upper range is exclusive
    Dim num2 As Integer = prng.Next(1, 11) '1-10 upper range is exclusive
End Sub
于 2013-06-11T12:57:21.047 回答
0

你有num1 = value 并且num2 = value

值只是我们正在创建的一个变量。

randomvalue = CInt(Int((upperbound - lowerbound + 1) * Rnd() + lowerbound))

所以对于你的代码:

 Dim num1 As Integer = CInt(Int((10 * Rnd()) + 1))

 Dim num2 As Integer = CInt(Int((10 * Rnd()) + 1))

本例使用 Rnd 函数生成一个 1 到 6 范围内的随机整数值。VB

' Initialize the random-number generator.
Randomize()
' Generate random value between 1 and 6.
Dim value As Integer = CInt(Int((6 * Rnd()) + 1))

http://msdn.microsoft.com/en-us/library/f7s023d2(v=VS.80).aspx

于 2013-06-11T12:57:02.063 回答