|
-
Jul 28th, 2002, 11:12 AM
#1
Thread Starter
Lively Member
Reading a String's Contents as a Variable Name
I have a variable called GenericVar that, in different situations, will hold the names of other variables. I want to use the value of GenericVar (which holds the name of another variable) to change the contents of the other variable using GenericVar's contents to refer to the variable's name. For example:
Dim GenericVar as String = "FloorChk"
Dim FloorChk as String = "Dirty"
GenericVar = "Clean" 'would be the same as saying FloorChk = "Clean"
I want the program to assign "The Floor is clean" to FloorChk after it sees that the contents of GenericVar = the name of the variable FloorChk.
So i want the result of the above code to be GenericVar = "FloorChk" and FloorChk = "Clean"
So what i'm trying to do is to get the program to treat the string inside the variable GenericVar as a variable name itself instead of the contents of a variable. So if GenericVar contains "FloorChk" then saying GenericVar = "Clean" would be the same as saying FloorChk = "Clean"
Is this possible? Or is it possible to actually change the name of GenericVar? like GenericVar.NewVariableName = FloorChk so now GenericVar would no longer exist as it has been changed to FloorChk. (i no there's nothing called ".NewVariableName" but just used it to try and make things clearer)
Thanks.
PS. i want to do this because i have several checkboxes FloorChk, WallChk, TableChk, etc. Each of these, when checked, displays the default contents of a variable (Floor, Wall, Table, etc) like "A rough dirty floor." I want the user to be able to rightclick on any of the checkboxes and be able to edit the contents of the variable, but i have far too many checkboxes to go into each sub and manually enter: if RightClick then Floor = ...etc. so instead i want to do something like: if RightClick then GenericVar = ...etc.
This is what i have:
Code:
Private Sub ContextMnuOption_Click (....etc) Handles ..etc.
If RightClick.SourceControl.Name.EndsWith("Chk") Then
GenericVar = RightClick.SourceControl.Name.Substring(0, RightClick.SourceControl.Name.Length - 3)
GenericVar = InputBox ("Enter your custom text")
End If
It doesn't work though b/c the contents of GenericVar isn't treated as a variable name. So i'm trying to see if it is possible to get the program to treat it as such.
Last edited by Psychotron; Jul 28th, 2002 at 12:24 PM.
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
|