|
-
Mar 8th, 2007, 10:46 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] how to parameter the name of the property of a variable
how to parameter the name of the property of a variable
I have this code for example:
if (drpDefaultLanguage.SelectedValue == "EN") then
lstKeyWords.Items.Add(txtKeywordEN.Text);
else if (drpDefaultLanguage.SelectedValue == "FR") then
lstKeyWords.Items.Add(txtKeywordEN.Text)
else if (drpDefaultLanguage.SelectedValue == "ES") then
lstKeyWords.Items.Add(txtKeywordES.Text)....etc
I need to put a variable called mySuffix which will hold one of the values : EN, FR, ES
So that instead of accessing the french value using: txtKeywordEN.Text it will be something that looks like: txtKeywordmySuffix.Text. So mySuffix is not a litteral but a variable itself.
This will allow me not to write the same code above: if else if else if ...... for as many langages as i have. Sometimes the total languages can be few dozens and that d be a lot of typing to hard code the loops like that.
Is that possible pls and how
Thanks
Thanks a lot for your help.
-
Mar 8th, 2007, 11:38 AM
#2
Re: how to parameter the name of the property of a variable
Code:
Controls("txtKeyword" + mySuffix).Text
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Mar 8th, 2007, 04:53 PM
#3
Thread Starter
Fanatic Member
Re: how to parameter the name of the property of a variable
that s cool amigo thank thee
Thanks a lot for your help.
-
Mar 8th, 2007, 06:00 PM
#4
Re: [RESOLVED] how to parameter the name of the property of a variable
I would suggest not using the names like that. Store the controls in a Dictionary keyed on the suffix:
vb Code:
Dim myDictionary As New Dictionary(Of String, TextBox)
myDictionary.Add("EN", Me.txtKeywordEN)
myDictionary.Add("FR", Me.txtKeywordFR)
myDictionary.Add("ES", Me.txtKeywordES)
You can then simply do this:
vb Code:
lstKeyWords.Items.Add(myDictionary(CStr(drpDefaultLanguage.SelectedValue)).Text)
-
Mar 8th, 2007, 07:00 PM
#5
Thread Starter
Fanatic Member
Re: [RESOLVED] how to parameter the name of the property of a variable
yeah that s true, may be better performance as well.
Thanks jmcilhinney
Thanks a lot for your help.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|