use counter variable when referencing control

G

Guest

I'm learning vb, coming from a Perl background. I want to know how to
reference a form element by using a counter variable in the element's name.
For instance, let's say I have a form with 10 textboxes named textbox1
through textbox 10 and I have a for loop and I want to populate the text in
the textboxes with the numbers 1 through 10 and I want to reference the
textbox names by using the counter, something like this

for x = 1 to 10
textbox(x).text = x
next

what particular characters do I use around the x to tell vb I want it to
interpret the value of x and use it at the end of the form element's name?

Hopefully I'm explaining myself properly.

BTW, if anyone knows perl, it would be the vb equivalent of the { }
characters.

Any help would be greatly appreciated.
 
H

Herfried K. Wagner [MVP]

mdiddy said:
I'm learning vb, coming from a Perl background. I want to know how to
reference a form element by using a counter variable in the element's
name.
For instance, let's say I have a form with 10 textboxes named textbox1
through textbox 10 and I have a for loop and I want to populate the text
in
the textboxes with the numbers 1 through 10 and I want to reference the
textbox names by using the counter, something like this

for x = 1 to 10
textbox(x).text = x
next

what particular characters do I use around the x to tell vb I want it to
interpret the value of x and use it at the end of the form element's name?


\\\
Private m_TextBoxes() As TextBox = {Me.TextBox1, Me.TextBox2, ...}
..
..
..
For Each txt As TextBox In m_TextBoxes
txt.Text = ...
Next txt
///

Accessing controls by their names or indices
<URL:http://dotnet.mvps.org/dotnet/faqs/?id=controlbynameindex&lang=en>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top