|
-
Oct 17th, 2008, 01:10 AM
#1
Thread Starter
Addicted Member
[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
-
Oct 17th, 2008, 05:35 AM
#2
Member
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)
-
Oct 17th, 2008, 05:46 AM
#3
Re: Simple Textbox Arrays
What specifically have you found to be complicated about TextBox arrays?
-
Oct 17th, 2008, 06:36 PM
#4
Thread Starter
Addicted Member
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
-
Oct 17th, 2008, 07:00 PM
#5
Thread Starter
Addicted Member
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
-
Oct 17th, 2008, 07:13 PM
#6
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.
-
Oct 17th, 2008, 07:33 PM
#7
Thread Starter
Addicted Member
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
-
Oct 17th, 2008, 07:46 PM
#8
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
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Oct 17th, 2008, 08:27 PM
#9
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
-
Oct 17th, 2008, 08:37 PM
#10
Re: Simple Textbox Arrays
 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
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Oct 17th, 2008, 09:07 PM
#11
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
-
Oct 18th, 2008, 05:47 AM
#12
Thread Starter
Addicted Member
Re: Simple Textbox Arrays
thanks everyone for your help
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|