|
-
Nov 12th, 2010, 08:18 AM
#1
Thread Starter
Lively Member
[RESOLVED] Simple Array Question
Okay, I've looked but I can't work out arrays for textboxes and labels. So, using 2 textboxes, how do I do the following in VB.Net?
Code:
For x = 1 to 2
if x = 1 then
txtbox(x).text = "One"
else
txtbox(x).text = "Two"
end if
next x
Any links, help out there? Thanks.
-
Nov 12th, 2010, 08:36 AM
#2
Re: Simple Array Question
try this:
vb Code:
dim txtbox() as textbox = {textbox1, textbox2}
For x = 1 to 2
if x = 1 then
txtbox(x - 1).text = "One" 'arrays are zero based
else
txtbox(x - 1).text = "Two"
end if
next x
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Nov 12th, 2010, 08:57 AM
#3
Thread Starter
Lively Member
Re: Simple Array Question
Yep that works. Thanks a lot! And another question, is this the correct way of doing it in vb.net? I read something about arrays not being offered, or we don't need to use arrays, in vb.net. Something about the controls collection. So, if there is another better way, or more correct way, what is it?
-
Nov 12th, 2010, 10:28 AM
#4
Re: Simple Array Question
before vb.net you could copy a control, say textbox1 + paste it, then the original textbox would be textbox1(0) + the new textbox would be textbox1(1), but it doesn't work that way in vb.net
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Nov 14th, 2010, 01:31 AM
#5
Thread Starter
Lively Member
Re: Simple Array Question
That's true. So my question is, how does it work in vb.net? When I create a textbox and then another textbox I get "TextBox1" and "TextBox2." Is there a way I can reference those numbers that are attached to the name of the textboxes? Or am I suppossed to do it another way? Overall I'd like to learn how to code it the proper way. Thanks for the help.
-
Nov 14th, 2010, 08:34 AM
#6
Re: Simple Array Question
you can reference them with an array as i showed you in post #2
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Nov 14th, 2010, 09:06 AM
#7
Thread Starter
Lively Member
Re: Simple Array Question
you can reference them with an array as i showed you in post #2
Yeah sorry, that was a poorly worded question on my part. Well ok, I'll do it that way then. Problem solved. Cheers.
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
|