FaheemAhmadGul
asked on
How to pass the name of a Bolean variable in a String Variable and setting the Boolean Variable True Using the String Variable.
I have a Global Boolean variable in my project in Visual Basic. named YesNo01
I wish to make it True through the Click event of a Button . However, instead of setting it True directly by using this Boolean Variable’s own name, I wish to set it True using a String Variable that is carrying its name.
So what I am looking for is something like this:
1. Dim YesNo01 As Boolean
2. Dim myString as String
3. myString = “YesNo01”
4. myString = True
I had hoped that the 4th line of code will make YesNo01 = True, but this does not work.
I wish to know if it is possible to achieve something like this. That is passing the name of one Boolean Variable in a String Variable and then setting the orginal Boolean variable true using that string variable. I hope I have been able to clarify my question.
Thank you for your help.
Best wishes
Is this VB6 or VB.Net?
How are you making the variable global? Is it a Public member in a Module?...or a Shared member in a Class?
How are you making the variable global? Is it a Public member in a Module?...or a Shared member in a Class?
ASKER
Thank you for your comments experts. My apologies for the delay in responding to your comments.
This is VB.NET. I have declared this in Module1 of my project as follows:
Public YesNo01 As Boolean
This is VB.NET. I have declared this in Module1 of my project as follows:
Public YesNo01 As Boolean
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Exceptional ! ! !
As this was a far more difficult question than I originally thought I am increasing the points to 400 before accepting Idle_Mind's solution.
Dear Idle_Mind System Reflection seems to be a very helpful yet difficult concept. I wonder if you would consider writing an article in EE sometime explaining how to use it in difficult scenarios.
Many thanks.
As this was a far more difficult question than I originally thought I am increasing the points to 400 before accepting Idle_Mind's solution.
Dear Idle_Mind System Reflection seems to be a very helpful yet difficult concept. I wonder if you would consider writing an article in EE sometime explaining how to use it in difficult scenarios.
Many thanks.
ASKER
Many thanks. It was brilliant ! !
There is an AddressOf() operator, but it only refers to functions.
You could consider using an array of variables, with named constants to help with readability, perhaps using an Enum class
Dim YesNo(2) as Boolean
Enum MyBool (YesNo00, YesNo01, YesNo02)
YesNo(YesNo01) = true