I have the following code in my program which adds all the items from a .txt to a listbox when the form loads.
I later use the following code in a button to generate random entries from the listbox into a locked textbox
My problem is that when I load the file into the listbox - it seems to add 2 "empty clickable options" if you understand..
so when I go to generate one, it sometimes fills the box with one of the empty options.
Can someone give me a line or two of code that will remove any empty options
- I've also check the .txt file and it doesn't have any blank lines that I can see!
Thanks!
Code:
Dim words As String = My.Computer.FileSystem.ReadAllText("location blah blah.txt") ' reads file to listbox and knows each item is on a new line
Dim wordssplitter As String() = words.Split(vbNewLine)
ListBox1.Items.AddRange(wordssplitter)Code:
Dim question1 As Long
Randomize()
question1 = Int(Rnd() * ListBox1.Items.Count) 'gets one random item from list / puts in label/ removes it
TextBox1.Text = ListBox1.Items(question1)
ListBox1.Items.RemoveAt(question1)so when I go to generate one, it sometimes fills the box with one of the empty options.
Can someone give me a line or two of code that will remove any empty options
- I've also check the .txt file and it doesn't have any blank lines that I can see!
Thanks!