I have two listboxes and one text box. lbxData is already populated with strings (ex; car, boat, motorcycle) I have a text box (tbxRandom) for user input to choose the number of random strings they want generated and placed in the other listbox (lbxRandom) when clicking btnRandom. Here is what I have but keep getting an error. mylist.addrange(str) "value cannot be null. parameter name: collection
can anyone tell me what i'm doing wrongCode:Dim Str As String 'Declare a List Dim myList As New List(Of String) 'Mylist gets the values of the existing array myList.AddRange(Str) 'Declare random Dim rnd As New System.Random 'This holds the generated random number Dim randomNumber As Integer = 0 Me.lbxRandom.Items.Clear() Dim count As Integer = 0 'textbox for user to choose the number of randomly generated items If Integer.TryParse(tbxRandom.Text, count) Then 'Keep looping until all items generated Do While count <> 0 'Generate randomNumber randomNumber = rnd.Next(0, myList.Count) 'Add current item to listbox Me.lbxRandom.Items.Add(myList(randomNumber)) 'Remove the used item so it can't be used again myList.RemoveAt(randomNumber) 'Reduce count by 1 count -= 1 Loop Else MessageBox.Show("Problem with that number you entered") End If




Reply With Quote