Avatar of FaheemAhmadGul
FaheemAhmadGul
Flag 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.
.NET ProgrammingVisual Basic Classic

Avatar of undefined
Last Comment
kaufmed

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
kaufmed

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Mike Tomlinson

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"?
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
kaufmed

NP. Glad to help  : )
Your help has saved me hundreds of hours of internet surfing.
fblack61