Solved

Build a Conditional If structure  dynamically!

Posted on 2014-02-18
2
257 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
2 Comments
 
LVL 35

Accepted Solution

by:
Robert Schutt earned 500 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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Ever notice how you can't use a new drive in Windows without having Windows assigning a Disk Signature?  Ever have a signature collision problem (especially with Virtual Machines?)  This article is intended to help you understand what's going on and…
Healthcare organizations in the United States must adhere to the guidance of both the HIPAA (Health Insurance Portability and Accountability Act) and HITECH (Health Information Technology for Economic and Clinical Health Act) for securing and protec…
This video will demonstrate how to find the puppet warp tool from the edit menu and where to put the points to edit.
Video by: Tony
This video teaches viewers how to export a project from Adobe Premiere Pro and the various file types involved.

743 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now