Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Switch with If/else statement ?

  • 04-07-2007 1:15pm
    #1
    Registered Users, Registered Users 2 Posts: 8,070 ✭✭✭


    Hey im using flex, actionscript 3
    -Taking in an XML file , E4X
    -Need to query it

    cc.JPG
    if(inputB.text==(""))
    {
    searchResult = dataDetails.person.(forename==inputA.text);
    Answer.htmlText = searchResult;
    }
    
    else if(inputA.text==(""))
    {
    searchResult = dataDetails.person.(surname==inputB.text);
    Answer.htmlText = searchResult;
    }
    else
    {
    searchResult = dataDetails.person.((forename==inputA.text)&&(surname==inputB.text));
    Answer.htmlText = searchResult; 
    }
    


    - If/else statement did fine to get all combinations of First/Last name where result is returned when either is queryed OR when both match

    Problem now is that each person also has a date associated with them(later a city too),
    im not sure how to integrate this in, should i be using a switch ? if so what
    would be the input for the switch statement ? bit confused.:confused:


Comments

  • Registered Users, Registered Users 2 Posts: 2,002 ✭✭✭Cionád


    Ok, its been a very long time since i've done anything like this...if ever :eek:

    That is JAVA, right?


  • Registered Users, Registered Users 2 Posts: 8,070 ✭✭✭Placebo


    actionscript 3 but notation is similar to Java/C
    i just need help with the algorithm.


  • Registered Users, Registered Users 2 Posts: 2,002 ✭✭✭Cionád


    Ok, yeah i understand what you mean now.

    In the short term you can increase the number of possibilities to 9 (i think) taking into account all the possiblities... but this is not practical, especially if you plan adding more details.

    I dont know much about switch but im pretty sure its "bad" programming to use it..

    what about something like one statement where you tick all the boxes where a date/ firstname ./etc is present, then have a for loop (for the amount of boxes ticked do)
    input.2 && input.5 && input.6 etc where the number represents the attribute (or box) searched...


  • Registered Users, Registered Users 2 Posts: 8,070 ✭✭✭Placebo


    hmm, i dont understand? can you explain it further?
    i got the switch working, gonna try nest in some more statements, not sure what use using switch was at all !
    switch(true)
    {
    case(inputB.text==("")):
    searchResult = dataDetails.person.(forename==inputA.text);
    Answer.htmlText = searchResult;
    break;    
    		  
    case(inputA.text==("")):   
    searchResult = dataDetails.person.(surname==inputB.text);
    Answer.htmlText = searchResult;
    break;
    			
    case(inputA.text!=("")&&(inputB.text!=(""))):
    searchResult = dataDetails.person.((forename==inputA.text)&&(surname==inputB.text));
    Answer.htmlText = searchResult; 
    break;
    }   
    


  • Registered Users, Registered Users 2 Posts: 8,070 ✭✭✭Placebo


    anyone ? i dont think i should even be using if/else statements, it will be too long And will be hacked together !:(


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 21,264 ✭✭✭✭Hobbes


    How about something like...

    searchString = ""

    Then individual IFs after that appending to the search string if the condition is met. Then run the search on the final string.

    This will stop chained if statements (which are prone to hard debugging) and you will only have one command that executes the search making it easier to maintain if you need to edit that syntax later.


  • Registered Users, Registered Users 2 Posts: 8,070 ✭✭✭Placebo


    hey i dont quite get you
    are you saying i should put each query [eg: Fname] into a string variable then apply search string on it and if it stays true then go on to next... etc ?


    thanks for the reply


Advertisement