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

Retrieve Textbox by its name ?

P: n/a
Hi,

I have an application with a lot of Textbox.
Do you know if I can set any Textbox Text only with the string name of the
Textbox.

Example : For the Textbox REXENP_CATEGW could I set the Text with its string
name "REXENP_CATEGW"
So I don't use 'REXENP_CATEGW.Text' but GetItem("REXENP_CATEGW").Text

Thank's.
Nov 20 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Here is an example :
I want to replace this code
Textbox1.Text = "....."
Textbox2.Text = "....."
Textbox3.Text = "....."
Textbox4.Text = "....."

By a code like this one :
Dim i as integer
For i = 1 to 4
GetItem("Textbox" & i.ToString()) = "...."
Next
Does the function "GetItem" exist ???

Thank's.
Nov 20 '05 #2

P: n/a
* "Te-Deum" <te*****@wanadoo.fr> scripsit:
I have an application with a lot of Textbox.
Do you know if I can set any Textbox Text only with the string name of the
Textbox.

Example : For the Textbox REXENP_CATEGW could I set the Text with its string
name "REXENP_CATEGW"
So I don't use 'REXENP_CATEGW.Text' but GetItem("REXENP_CATEGW").Text


Add all of the controls you want to access by name to a 'Hashtable', use
their names as keys and a reference to the control as value.

--
Herfried K. Wagner
MVP VB Classic, VB.NET
<http://www.mvps.org/dotnet>

Dilbert's words of wisdom #18: Never argue with an idiot. They drag you down
to their level then beat you with experience.
Nov 20 '05 #3

P: n/a
"Te-Deum" <te*****@wanadoo.fr> schrieb
Here is an example :
I want to replace this code
Textbox1.Text = "....."
Textbox2.Text = "....."
Textbox3.Text = "....."
Textbox4.Text = "....."

By a code like this one :
Dim i as integer
For i = 1 to 4
GetItem("Textbox" & i.ToString()) = "...."
Next
Does the function "GetItem" exist ???

Thank's.


Why not put the textboxes in an array? Variable names are out of interest at
runtime (IMHO).

private m_Textboxes as textbox()
'...
In OnLoad/Form_Load:
m_textboxes = new textbox(){textbox1, textbox2, textbox3, textbox4}

You can also use expressive names for the textboxes.

Loop:
for i=0 to 3
m_textboxes(i) = "...."
next i
--
Armin

http://learn.to/quote
http://www.plig.net/nnq/nquote.html

Nov 20 '05 #4

P: n/a
* "Te-Deum" <te*****@wanadoo.fr> scripsit:
Here is an example :
I want to replace this code
Textbox1.Text = "....."
Textbox2.Text = "....."
Textbox3.Text = "....."
Textbox4.Text = "....."

By a code like this one :
Dim i as integer
For i = 1 to 4
GetItem("Textbox" & i.ToString()) = "...."
Next
Does the function "GetItem" exist ???


Have a look at Armin's suggestion.

'GetItem' doesn't exist, but:

<http://groups.google.de/groups?selm=%23kGYk5IgDHA.164%40tk2msftngp13.phx.g bl>

--
Herfried K. Wagner
MVP VB Classic, VB.NET
<http://www.mvps.org/dotnet>

Dilbert's words of wisdom #18: Never argue with an idiot. They drag you down
to their level then beat you with experience.
Nov 20 '05 #5

P: n/a
Thank's, the solution by Armin seems to be what I search.
Nov 20 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.