Link to home
Create AccountLog in
Avatar of FaheemAhmadGul
FaheemAhmadGulFlag for United Kingdom of Great Britain and Northern Ireland

asked on

How to pass the name of a Bolean variable in a String Variable and then Use that String Variable as a Replacement for the Name of the Boolean Variable in Code

This question is related to another question I asked on the Forum today and which was very kindly answered by Idle_Mind.

I have a Global Boolean variable in my project in a Visual Basic  .NET Project  named    YesNo01. This YesNo01 is declared in a Module1 of my Project.

I wish to write some code along the following lines
1. If  YesNo01 = True Then
2. MessageBox.Show (“YesNo01 = True”)
3. Else
3. MessageBox.Show (“YesNo01 = False”)
4. End if

However  I do not want to use the actual Name of  YesNo01  in statement No 1. Instead I wish to say something like the following:

Dim myString as String
myString = “YesNo01”
If myString = True Then
MessageBox.Show (“YesNo01 = True”)
Else
MessageBox.Show (“YesNo01 = False”)
End if

Thank you for your help in anticipation.
ASKER CERTIFIED SOLUTION
Avatar of kaufmed
kaufmed
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
The most ~direct~ route would be using a Dictionary as kaufmed suggests.  The Reflection approach I posted in your last question can't really be shortened.  It can be placed into a function I suppose...

How are you going to use this?  What is the "big picture"?
Avatar of FaheemAhmadGul

ASKER

Excellent many thanks.
Idle_MInd the big picture is hard to explain briefly, but in my code somewhere I need to check if one of the several YesNo01 variables is true before the rest of the code runs. I cannot tell the code directly in advance which of the several YesNo variables (YesNo1, YesNo02 etc ) my code should check the value of before running further, but I can provide my code the value of YesNo variable it should check through a string variable. Hence these two questions related in theme. Many thanks both of you for your kind help.
Regards
NP. Glad to help  : )