I'm trying to create a program which selects textboxes from the list at random and generate random numbers from 1 to 5 in those textboxes, but with no success. I have 10 textboxes named Textbox1- Textbox10, 1 textbox named TxB1 and 1 button. In TxB1 user should specify number of selected at random textboxes. For example: user has specified number 4 in TxB1, has clicked button1 and then numbers from 1 to 5 should appear in 4 different textboxes choosed at random. Here is the code I tried with no luck...
Dim rn As New Random
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim RandomNumberAHigh2 As Integer = 4
Dim RandomNumberALow2 As Integer = 1
Dim index2 As Integer = rn.Next(1, TxB1.Text)
Dim MyListOfTextBoxes() As TextBox = {TextBox1, TextBox2, TextBox3, TextBox4, TextBox5, TextBox6, TextBox7, TextBox8, TextBox9, TextBox10}
For index = 0 To 9
Dim RandomNumberAHigh As Integer = 12
Dim RandomNumberALow As Integer = 1
Dim Random As Integer = 0
For i As Integer = 0 To index2
MyListOfTextBoxes(index2).Text = Int((RandomNumberAHigh - RandomNumberALow + 1) * Rnd() + RandomNumberALow)
Next
Next
End Sub
Aucun commentaire:
Enregistrer un commentaire