By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,527 Members | 1,184 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,527 IT Pros & Developers. It's quick & easy.

use counter variable when referencing control

P: n/a
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.
Nov 21 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"mdiddy" <md****@discussions.microsoft.com> schrieb:
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>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #2

P: n/a
"mdiddy" <md****@discussions.microsoft.com> schrieb:
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>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.