[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.
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
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?
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
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.
Re: Simple Array Question
you can reference them with an array as i showed you in post #2
Re: Simple Array Question
Quote:
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.