?
Solved

Build a Conditional If structure  dynamically!

Posted on 2014-02-18
2
Medium Priority
?
281 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

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

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

All of the resources available today make learning a new digital media easier than ever-- if you know where to begin. This is a clear, simple guide to a few of the basic digital art mediums and how to begin learning them on your own.
This month, Experts Exchange’s free Course of the Month is focused on CompTIA IT Fundamentals.
Video by: Tony
This video teaches viewers how to export a project from Adobe Premiere Pro and the various file types involved.
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

800 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