Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Build a Conditional If structure  dynamically!

Posted on 2014-02-18
2
Medium Priority
?
288 Views
Last Modified: 2014-02-18
I want to allow users a  simple search  with  2 textboxes and one combo box

[                   ]  or/and [              ]

My conditional If  would be something like this:

string sele = "";
if   (operator.Text == "or")
                            {
                            sele = "text.Contains(textbox1) == true || text.Contains(textbox2)";
                            }
                        else
                            {
                            sele = "text.Contains(textbox1) == true && text.Contains(textbox2)";
                            }

                                 // now I would like to use      
                            if (sele)                   ----------> not allowed in c#
                               {
                                   lot a code here
                               }

Any help for a Proof of Concept programmer?
0
Comment
Question by:novreisb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 35

Accepted Solution

by:
Robert Schutt earned 2000 total points
ID: 39867579
I see 2 options:

1 - make sele a boolean and assign without the quotes
bool sele = false;
if   (operator.Text == "or")
                            {
                            sele = text.Contains(textbox1.Text) || text.Contains(textbox2.Text);
                            }
                        else
                            {
                            sele = text.Contains(textbox1.Text) && text.Contains(textbox2.Text);
                            }

                            if (sele)
                               { 
                                   //lot a code here
                               }

Open in new window

2 - use boolean logic to make 1 big if statement (of which only 1 part will be executed so no waste of resources)
if (
    ( operator.Text == "or"  && (text.Contains(textbox1.Text) || text.Contains(textbox2.Text) ) )
    ||
    ( operator.Text == "and" && (text.Contains(textbox1.Text) && text.Contains(textbox2.Text) ) )
)
                               { 
                                   //lot a code here
                               }

Open in new window

0
 

Author Closing Comment

by:novreisb
ID: 39867878
Perfect!
Sometimes we put an idea in your head and forget other options
thks Robert
0

Featured Post

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How many times a day do you open, acknowledge, or close an IT incident? What’s your process? Do you have a process depending on the incident, systems involved, and other factors? New Relic Alerts gives you options for how you interact with notifica…
One-stop solution for Exchange Administrators to address all MS Exchange Server issues, which is known by the name of Stellar Exchange Toolkit.
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question