|
-
Jul 8th, 2010, 01:51 PM
#1
Thread Starter
Member
Variable Question: Use variable value to set another variable of that values name
Okay here's my question.
How would I use a variables value to be used to set or get another variables value?
Here's an example.
Let's say I have 3 variables but actually have many more
House = "Big"
Car = "Fast"
Pet = "Dog"
Now I have a function that queries a table to get some data and one of the fields is a variable name such as Pet
something like
VariableCheck = GetVariableFieldValue() // This returns Pet
so VariableCheck = Pet
So rather than having a Huge select case statement such as:
Select Case VariableCheck
Case "House"
txtValue.text = House
Case "Car"
txtValue.Text = Car
Case "Pet"
txtValue.Text = Pet
End Select
I need some kind of varValueVariable function.
txtValue.Text = VarValueOf(VariableCheck)
and a set value of vunction
SetVarValueOf(VariableCheck) = "Cat"
Thanks for all your help
Last edited by Mythos44; Jul 8th, 2010 at 02:05 PM.
-
Jul 8th, 2010, 02:36 PM
#2
Frenzied Member
Re: Variable Question: Use variable value to set another variable of that values name
 Originally Posted by Mythos44
Okay here's my question.
How would I use a variables value to be used to set or get another variables value?
Here's an example.
Let's say I have 3 variables but actually have many more
House = "Big"
Car = "Fast"
Pet = "Dog"
Now I have a function that queries a table to get some data and one of the fields is a variable name such as Pet
something like
VariableCheck = GetVariableFieldValue() // This returns Pet
so VariableCheck = Pet
So rather than having a Huge select case statement such as:
Select Case VariableCheck
Case "House"
txtValue.text = House
Case "Car"
txtValue.Text = Car
Case "Pet"
txtValue.Text = Pet
End Select
I need some kind of varValueVariable function.
txtValue.Text = VarValueOf(VariableCheck)
and a set value of vunction
SetVarValueOf(VariableCheck) = "Cat"
Thanks for all your help
Um, if your GetVariableFieldValue() function returns "Pet", and you want to set a textbox value equal to that string, you don't need a switch statement, just do
Code:
txtValue.Text = VariableCheck
Likewise for setting it's value, you would do:
Code:
VariableCheck = "Cat"
Unless I just don't get it...
Justin
-
Jul 8th, 2010, 02:52 PM
#3
Thread Starter
Member
Re: Variable Question: Use variable value to set another variable of that values name
Okay the problem is I do not havea function that will do this. I do not know how to do this.
I want to reverance a variable by the string value of another variable which it's string value is the variable name of the first variable.
FirstVar = "Pet"
SecondVar = "FirstVar"
I want to somehow use the value of SecondVar which is "FirstVar" to set FristVar variable's value or what ever variable name is in SecondVar.
I'm not sure how to explain it further.
-
Jul 8th, 2010, 04:20 PM
#4
Hyperactive Member
Re: Variable Question: Use variable value to set another variable of that values name
 Originally Posted by MonkOFox
Um, if your GetVariableFieldValue() function returns "Pet", and you want to set a textbox value equal to that string, you don't need a switch statement, just do
Code:
txtValue.Text = VariableCheck
Likewise for setting it's value, you would do:
Code:
VariableCheck = "Cat"
Unless I just don't get it...
Justin
Look at his first post again, if it returns Pet he would actually want the text to read "Dog" since that is what corresponds with the variable name Pet.
-
Jul 8th, 2010, 04:56 PM
#5
Re: Variable Question: Use variable value to set another variable of that values name
It seems like you might do this with a dictionary (of String,String), where the key is what you are calling the variable name and the value is just that. Therefore, there would be a dictionary with entries:
"House","Big"
"Car","Fast"
"Girlfriend","Dog"
or whatever your example actually was. Now, you can pass in the key, which is what your GetVariableFieldValue method is returning, and get out the value for that key, which is what you are looking for.
My usual boring signature: Nothing
 
-
Jul 8th, 2010, 05:09 PM
#6
Re: Variable Question: Use variable value to set another variable of that values name
You cant do what you described I'm afraid - I would suggest the same thing that Shaggy mentioned, using a Dictionary.
-
Jul 9th, 2010, 06:16 AM
#7
Thread Starter
Member
Re: Variable Question: Use variable value to set another variable of that values name
Thank you all 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
|