Is it possible to add multiple rows to a listbox at the same time?
Simply use a loop or multiple AddRow statements?
Thanks.
App crashes.
My Code
Dim TheRandom As New Random
Dim a As Integer
Dim b As Integer
Dim HowMany As Integer = TextField3.Text.Val
Do
a = TheRandom.InRange(TextField1.Text.Val, TextField2.Text.Val)
Listbox1.AddRow(Str(a))
Loop Until b = HowMany
Try below untested.
Dim TheRandom As New Random
Dim a As Integer
Dim b As Integer
Dim HowMany As Integer = val (TextField3.Text)
Do a = TheRandom.InRange(val (TextField1.Text), val (TextField2.Text))
Listbox1.AddRow str(a)
Loop Until b = HowMany
[quote=39991:@Shane Gibbs]App crashes.
My Code
[code]
Dim TheRandom As New Random
Dim a As Integer
Dim b As Integer
Dim HowMany As Integer = TextField3.Text.Val
Do
a = TheRandom.InRange(TextField1.Text.Val, TextField2.Text.Val)
Listbox1.AddRow(Str(a))
Loop Until b = HowMany
[/code][/quote]
What error? Have you set a break point and stepped through the code?
[quote=39992:@Paul Budd]Try below untested.
Dim TheRandom As New Random
Dim a As Integer
Dim b As Integer
Dim HowMany As Integer = val (TextField3.Text)
Do a = TheRandom.InRange(val (TextField1.Text), val (TextField2.Text))
Listbox1.AddRow str(a)
Loop Until b = HowMany[/quote]
That makes sense. I’ll try it out in the later today.
~Night~
[quote=39991:@Shane Gibbs]App crashes.
My Code
[code]
Dim TheRandom As New Random
Dim a As Integer
Dim b As Integer
Dim HowMany As Integer = TextField3.Text.Val
Do
a = TheRandom.InRange(TextField1.Text.Val, TextField2.Text.Val)
Listbox1.AddRow(Str(a))
Loop Until b = HowMany
[/code][/quote]
Maybe your loop is missing an update of the b value
Do
a = TheRandom.InRange(TextField1.Text.Val, TextField2.Text.Val)
Listbox1.AddRow(Str(a))
b=b+1
Loop Until b = HowMany
[quote=39997:@Antonio Rinaldi]Maybe your loop is missing an update of the b value
Do
a = TheRandom.InRange(TextField1.Text.Val, TextField2.Text.Val)
Listbox1.AddRow(Str(a))
b=b+1
Loop Until b = HowMany
[/quote]
That works! Thanks!
If you’re starting with an empty listbox each time you could use the listcount property & do away with b altogether.
Thanks for the code optimization.
Subclass the ListBox, and put the loop in method, AddRows(n) code looks cleaner.
For things like this, you may consider extending the Listbox instead of subclassing it.
I’ve always subclassed ListBoxes, what is the advantage of extending it?
See the Extends Keyword page on the Wiki and/or the book 1 of the user guide ( UserGuide-Fundamentals.pdf ) page 124.
OK, thanks. I have so much other custom stuff I do with events and properties, I’ve always just subclassed the ListBox. Thanks for the tip!