• Resolved digiblogger

    (@digiblogger)


    Hello friend,

    i try to combine an if statement with the case statement.

    fieldname2 = amount (number)
    fieldname3 = source unit (dropdown)
    fieldname5 = target unit (dropdown)
    fieldname6-10 = other target units for category like speed, volume, distance, etc., all dropdowns

    What I try to achieve in words:

    Check fieldname3 for the unit (text string)
    Then, if source unit = m, check the target unit in fieldname5
    return results for all cases

    then if source unit = cm, check target unit in fieldname5
    return result for all cases

    This code is only if source unit is “m”.
    I gets no result.
    Maybe, if you can make it work, you can add a second switch block if fieldname3 = cm or something?

    `(function(){
    if(fieldname3 == ‘m’,
    switch(fieldname5)
    {
    case ‘mm’: return PREC(fieldname2/1000,2);
    case ‘cm’: return PREC(fieldname2/100,2);
    case ‘dm’: return PREC(fieldname2/10,2);
    case ‘m’: return PREC(fieldname2*1,2);
    case ‘km’: return PREC(fieldname2*1000,2);
    }
    )
    })()’

    Thank you so much

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

    (@codepeople)

    Hello @digiblogger

    Thank you very much for using our plugin. The correct structure would be:

    (function(){
        if(fieldname3 == 'm'){
            switch(fieldname5)
            {
                case 'mm': return PREC(fieldname2/1000,2);
                case 'cm': return PREC(fieldname2/100,2);
                case 'dm': return PREC(fieldname2/10,2);
                case 'm': return PREC(fieldname2,2);
                case 'km': return PREC(fieldname2*1000,2);
            }
        }
        /* The if here */
    })()

    I recommend checking the “Converter for Calculated Fields Form” complementary plugin:

    https://cff-bundles.dwbooster.com/product/converter

    By using it the equation could be implemented as follows:

    CFFCONVERTER(fieldname2, fieldname3, fieldname5, 2)

    Best regards.

    Thread Starter digiblogger

    (@digiblogger)

    Hello,

    thank you so much.
    I bought the converter, but it does not work for currencies. I think, for currencies, the CFF Currency Exchange AddOn is needed. And just for calculating USD to EUR, I don´t think I will spend 4 times more compared to the Converter plugin 🙂

    But thank you so much for the help with the code.
    Works like a charm

    Plugin Author codepeople

    (@codepeople)

    Hello @digiblogger

    Thank you very much for using our plugin.

    Best regards.

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

The topic ‘Combining IF and CASE’ is closed to new replies.