• Resolved torqueing

    (@torqueing)


    I’m trying to replicate a calculation from Excel and I cant seem to get it to work. I’m pretty sure I’m missing something from the logical operators. The field looks like this:
    IF((fieldname8, SP) * AND((fieldname7 > 2879.17)) , 2879.17, IF((fieldname8, SP) * AND(fieldname7, < 2879.17) , fieldname7 , IF(fieldname8, MP) * (AND(fieldname7 > 3629.17 , fieldname7) , 3629.17 , fieldname7)))

    Fieldname8 is a dropdown box with just 2 options: SP and MP, each with a number value.

    The Excel equation looks like this: =IF((B17="SP")*AND(B14>2879.17),2879.17,IF((B17="SP")*AND(B14<2879.17),B14,IF((B17="MP")*AND(B14>3629.17,B14),3629.17,B14)))
    Obviously B17 is fieldname7 and B14 is fieldname8 (a number)

    The page I need help with: [log in to see the link]

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author codepeople

    (@codepeople)

    Hello @torqueing,

    Our plugin is not Excel, and you cannot use the same structures. For example, you cannot compare the fieldname8 with the choices’ texts, in the equations only are used the values. So, the correct equation would be:

    
    (function(){
    if(fieldname8 == 2879.17 && 2879.17 < fieldname7) return 2879.17;
    if(fieldname8 == 2879.17 && fieldname7 < 2879.17) return fieldname7;
    if(fieldname8 == 3629.17 && 3629.17 < fieldname7) return 3629.17;
    return fieldname7;
    })()
    

    If you prefer to use the “IF” and “AND” operations distributed with the plugin, the equation would be:

    
    IF(AND(fieldname8 == 2879.17, 2879.17 < fieldname7), 2879.17, IF(AND(fieldname8 == 2879.17, fieldname7 < 2879.17), fieldname7, IF(AND(fieldname8 == 3629.17 && 3629.17 < fieldname7), 3629.17,fieldname7)))
    
    

    Actually, I prefer a more optimized implementation, all your equation is reduced to:

    
    MIN(fieldname8,fieldname7)
    

    Best regards.

    Thread Starter torqueing

    (@torqueing)

    Thankyou. You, my good man, are a genius 🙂

    If I could give you more than 5 stars I would

    Thread Starter torqueing

    (@torqueing)

    Although I’m having a different problem I think it’s in the same ballpark wrt syntax.

    This just doesn’t seem to work:

    (function(){
    if(fieldname7 < 1083.30) return 0 ;
    } 
    else if(fieldname7 > 1083.30 && fieldname7 < 1614.33) { 
    1001 * 0.005 + fieldname7 -1001 *002 ;
    }
    else { return 7 ;
    })()
    • This reply was modified 8 years, 2 months ago by torqueing.
    Plugin Author codepeople

    (@codepeople)

    Hello @torqueing,

    The number of symbols: “{” and “}” is incorrect, furthermore you are not using the “return” statements as should. The correct one is:

    
    (function(){
    if(fieldname7 < 1083.30){ return 0 ;}
    else if(1083.30 <= fieldname7 && fieldname7 < 1614.33) { return 1001*0.005+fieldname7-1001*002 ;}
    else { return 7;}
    })()
    

    or simply:

    
    (function(){
    if(fieldname7 < 1083.30) return 0 ;
    if(1083.30 <= fieldname7 && fieldname7 < 1614.33) return 1001*0.005+fieldname7-1001*002;
    return 7;
    })()
    

    Best regards.

    Thread Starter torqueing

    (@torqueing)

    Thanks again. I’ve never learned javascript so I’m trying to learn it through your examples and this on w3c schools

    if (time < 10) {
        greeting = "Good morning";
    } else if (time < 20) {
        greeting = "Good day";
    } else {
        greeting = "Good evening";
    }

    hahaha 🙂

    Plugin Author codepeople

    (@codepeople)

    Hello,

    Yes, but into a function structure you should use the “return” statement to return the result, for example, assuming that in your piece of code the time variable corresponds to the fieldname1 field, the equation would be:

    
    (function(){
    var greeting = "Good evening";
    if (fieldname1 < 10) {
        greeting = "Good morning";
    } else if (fieldname1 < 20) {
        greeting = "Good day";
    }
    return greeting;
    })()
    

    As you can see the equation is even simpler than the original code because the last “else” is unnecessary.

    Best regards.

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Dropdown Box Problems. Incorrect Format?’ is closed to new replies.