Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You are confusing VB.NET with VB6. They are drastically different from each other. In the future, when you look for examples, documentation, and help online, be sure to specify VB6 to ensure that you are dealing with the correct language. They are essentially two completely different languages.</p> <h2>VB6</h2> <p>In VB6, you need to initially seed the random number generator using the <code>Randomize</code> function. Then, to generate a random number, you must use the <code>Rnd</code> function, for instance:</p> <pre><code>Private Sub cmdjouer_Click(Index As Integer) Randomize() txt1.Text = Int((Rnd * 9) + 1) txt2.Text = Int((Rnd * 9) + 1) txt3.Text = Int((Rnd * 9) + 1) End Sub </code></pre> <h2>VB.NET</h2> <p><code>Math.Randomize</code> is a method in the Smart Personal Objects Technology (SPOT) namespace. I doubt that is what you are actually looking for. You probably just want to use the <code>System.Random</code> class, like this:</p> <pre><code>Private Sub cmdjouer_Click(sender As Object, e As EventArgs) Handles cmdjouer.Click Dim r As New Random() txt1.Text = r.Next(9).ToString() txt2.Text = r.Next(9).ToString() txt3.Text = r.Next(9).ToString() End Sub </code></pre> <p>As others have pointed out, you don't want to set your text box reference variable to the number (e.g. <code>txt1 = ...</code>). You need to set the <code>Text</code> property of the text box. </p> <p>Also, as was pointed out in the comments below, I called <code>Randomize</code> or created the <code>New Random</code> object inside the button's <code>Click</code> event. I did so to simplify the example, but in actuality, that would be bad practice. In either case, the seeding of the random number generator should, ideally, only happen once, typically when the application starts. By re-seeding the generator each time, it can cause the results to be less random.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload