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
Re: Variable Question: Use variable value to set another variable of that values name
Quote:
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
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.
Re: Variable Question: Use variable value to set another variable of that values name
Quote:
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.
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.
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.
Re: Variable Question: Use variable value to set another variable of that values name
Thank you all for your help.