Hi
can anyone teach me how to use visual basic to make a random number generate between 1 to 10
than
example:
if the generate number is 1 it will display "abc" on the textbox
if the generate number is 2 it will display "cba" on the textbox
Pls help me thank!
Loading

Scott LysleRank #49 · 31K reputationPosted Nov 16, 2006, 5:25 PM EST
Dim
rnd As New Random() Dim intRandom As IntegerintRandom = rnd.Next(0, 10)
MessageBox.Show(
"Random Number between 0 and 10: " & intRandom.ToString())Desmond Tan4 reputationPosted Nov 21, 2006, 5:48 AM EST
if can send me a sample pls... [email protected]...
Scott LysleRank #49 · 31K reputationPosted Nov 23, 2006, 10:33 PM EST
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim rnd As New Random()
Dim intRandom As Integer
intRandom = rnd.Next(0, 10) Select Case intRandom
Case 1
TextBox1.Text = "ABC"
Case 2
TextBox1.Text = "DEF"
Case 3
TextBox1.Text = "GHI"
Case 4
TextBox1.Text = "JKL"
Case 5
TextBox1.Text = "MNO"
Case 6
TextBox1.Text = "PQR"
Case 7
TextBox1.Text = "STU"
Case 8
TextBox1.Text = "VXY"
Case 9
TextBox1.Text = "ZAB"
Case 10
TextBox1.Text = "ZAC"
Case Else
TextBox1.Text = "AAA"
End Select
End Sub
Solitaire85 reputationPosted Dec 5, 2006, 2:34 PM EST
intRandom = rnd.Next(0, 10)
will generate a random number between 0 and 9. The second argument after Next must be 1 more than the upper limit of the range.
For the above example, you should use:
intRandom = rnd.Next(1, 11)