[RESOLVED] Simple Textbox Arrays
is there a way of creating an array of textboxes EASILY. iv read some other posts and they all are really complicated. all i need is something simple like this:
textbox(1)
textbox(2)
and then to be able to refer to the numbers through a variable like this:
i=1
textbox(i).text="hello world"
is there an easy way of doing this?
thanks in advance :)
Re: Simple Textbox Arrays
try this:
Dim textboxes(#) as textbox
I = (#
textbox(i).text="hello world"
(# = What ever number you want. (Dim textboxes(AS many as you want)
Re: Simple Textbox Arrays
What specifically have you found to be complicated about TextBox arrays?
Re: Simple Textbox Arrays
i just realised i made a big mistake. will the same array work with labels:
dim variable(#)as labels
i=(#
label(i).text="hello world"
will that work also?
thanks a lot
ill try it and get back to u anyway :D
Re: Simple Textbox Arrays
actually im using v2008 express and the code doesn't work this is what iv got:
at the very top:
dim bank(50) as label
then in a seperate piece of code in a button press i use this:
dim i as integer =0
for i =1 to 95
bank(i).text="hello world"
next
it executes but an error occurs when i press the button to run the code
please help me why wont it work
Re: Simple Textbox Arrays
You're specifying 50 as upper bound when you declare the label array, yet your for-loop goes all the way up to 95. ;)
Re: Simple Textbox Arrays
its still not working
should i do this:
dim var(3) as label = {var1, var2, var3}
dim i as integer =0
for i=1 to 3
var(i).text="hello world"
next
Re: Simple Textbox Arrays
try this:
vb Code:
Dim lbl(49) As Label
For x As Integer = 0 To 49
lbl(x) = New Label
Me.Controls.Add(lbl(x))
lbl(x).Location = New Point(0, x * lbl(x).Height)
lbl(x).Text = x.ToString
Next
Re: Simple Textbox Arrays
Hey,
As another alternative, you could use a Generic List of Type Label as follows:
Code:
Dim labels As New List(Of Label)
For x As Integer = 0 To 49
Dim label As New Label
label.Location = New Point(0, x * label.Height)
label.Text = x.ToString
Me.Controls.Add(label)
Next
Hope this helps!!
Gary
Re: Simple Textbox Arrays
Quote:
Originally Posted by gep13
Hey,
As another alternative, you could use a Generic List of Type Label as follows:
Code:
Dim labels As New List(Of Label)
For x As Integer = 0 To 49
Dim label As New Label
label.Location = New Point(0, x * label.Height)
label.Text = x.ToString
Me.Controls.Add(label)
Next
Hope this helps!!
Gary
you've declared a list + not used it
Re: Simple Textbox Arrays
Ha Ha!!!
Good point!!! I took the code that you gave and modified it to use a List of TextBox, but forgot to add the label into the List. I was just trying to provide another means of collecting the labels into a List, which doesn't require defines an upperbound to an array.
Here is the corrected code:
Code:
Dim labels As New List(Of Label)
For x As Integer = 0 To 49
Dim label As New Label
label.Location = New Point(0, x * label.Height)
label.Text = x.ToString
labels.Add(label)
Me.Controls.Add(label)
Next
Once you have created the list you can enumerate through them as follows:
Code:
For Each label As Label In labels
MessageBox.Show(label.Text)
Next
Gary
Re: Simple Textbox Arrays
thanks everyone for your help