Hi all, does anyone know why this is not working for me?
I have 15 textboxes i want to put 5 random numbers from 1 to 48 in 5 of this textboxes.
my CODE:
Dim lstInt As New List(Of Integer)
Dim lstTB As New List(Of TextBox)
Dim rndm As New Random
For Each ctrl In Controls.OfType(Of TextBox)()
lstTB.Add(ctrl)
Next
Private Sub btdraw1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btdraw1.Click
Dim lstPicked As New List(Of Integer)
For i As Integer = 1 To 48
Dim index As Integer = rndm.Next(0, lstInt.Count)
lstPicked.Add(lstInt(index))
lstInt.RemoveAt(index)
Next
For i As Integer = 0 To 5
CType(lstTB(i), TextBox).Text = lstPicked(i).ToString
Next
AM I DOING SOMETHING WRONG THERE error message what i get is this:
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
Inside your loop 1 to 48 you are trying to grab a value from lstInt() when lstInt is empty. You can easily see this if you step through your code in debug mode.
__________________ Burn the land and boil the sea
You can't take the sky from me
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET. subscribe