7
Answers

Use string array as identifier

Ijoran

Ijoran

16y
3.9k
1

I want to use a string array as an identifier to interact with a group of textboxes in a userform.

this would mean having code like

string[] Book = new string[5];

Book[1] = "Title"; Book[2] = "Author"; ...etc

Then I could use this to obtain information from the textbox.  e.g. MessageBox.Show (Userform.Book[1].Text.toString());

 

I don't seem to be able to find a way to convert/cast the string so I can use it to identify the TextBox in the Userform so would it be right to assume it is not possible?

Answers (7)
0
Ijoran

Ijoran

NA 7 0 16y

Looks like Form Controls are where I needed to be looking, thanks for yor help Dipal.

This goes for the hashtables as wel, cheers Ryan.

 

0
Ryan Alford

Ryan Alford

NA 2.3k 891.7k 16y
look into using a HashTable.  it uses key/value pairs.  there are a number of other Collections that you could look into.  using two separate string arrays is not the best way.
0
Dipal Choksi

Dipal Choksi

NA 11.6k 6.2m 16y

Hi,

Here is a link to an article that describes how to get the reference to a control on a windows form by passing the name of the control. You can adapt this code to use the values from your string array to set the Text for the text boxes.

http://www.eggheadcafe.com/articles/20040506.asp

Hope this helps...

0
Ijoran

Ijoran

NA 7 0 16y

Windows System Forms

And my guess is thats going to be the wrong answer to make me a happy camper.

0
Dipal Choksi

Dipal Choksi

NA 11.6k 6.2m 16y
Are you using ASP.Net or windows forms programming?
0
Ijoran

Ijoran

NA 7 0 16y

Yes.  Exactly.

I will be reading in the string information for the array from another document.  Each string will have another corresponding string with related data e.g.

Book[1] = "Title";  BookData[1] = "Dictionary";

Book[2] = "Author"; BookData[2] = "Samuel Johnson";

I will then loop through both array's and use Book[] to be the identifier for the textbox in the userform.  From here I can populate the textbox with BookData[] information.

Hope that makes sense.

 

 

 

0
Dipal Choksi

Dipal Choksi

NA 11.6k 6.2m 16y
Could you clarify your question a bit? Did you mean you wanted to store the names of the text boxes in the string array and at run-time, use the value contained in the string within the array as the identifier for the textbox?