Uniface User Forum

 View Only
  • 1.  Ternary Operator?

    Posted 08-12-2022 06:42
    Good Morning,

    What is the possibility of uniface having the ternary operator?


    ------------------------------
    Juliano Garcia
    Suport Analyst
    Coamo -Coop. Agropecuaria Mouraoense
    Campo Mourão BR
    ------------------------------


  • 2.  RE: Ternary Operator?

    Posted 08-12-2022 11:49

    Hi Juliano,

    If you mean a checkbox with True/False/Null: it's a widget option...

    Regards,
    Gianni



    ------------------------------
    Gianni Sandigliano
    IT
    ------------------------------



  • 3.  RE: Ternary Operator?

    Posted 08-12-2022 13:23
    Edited by Juliano Anoar Haoach Garcia 08-12-2022 13:23
    Hi Gianni,

    This tree state option I already know, it would be something like:

    v_result =  (a = true ? 'a' : 'b' )
    ;v_result  "a"


    ------------------------------
    Juliano Garcia
    Suport Analyst
    Coamo -Coop. Agropecuaria Mouraoense
    Campo Mourão BR
    ------------------------------



  • 4.  RE: Ternary Operator?

    Posted 08-13-2022 04:57

    Hi Juliano,

    Ah...what I usually use as IIF(condition, value1, value2).

    You can build a function by yourself, putting it into SYSTEM_LIBRARY:

    entry iif
    returns string
    params
       string pCond : IN
       string pOne    : IN
       string pTwo    : IN
    endparams
    if (pCond = "") return("")
    if ($condition(pCond) | $uppercase($rtrim($ltrim(pCond, " "), " ")) = "TRUE")
       return(pOne)
    else
       return(pTwo)
    endif
    end

    Take care to read about $condition into Uniface manuals.

    I hope it could help you.

    Regards,
    Gianni



    ------------------------------
    Gianni Sandigliano
    IT
    ------------------------------



  • 5.  RE: Ternary Operator?

    Posted 08-16-2022 15:31
    Thank you Gianni.

    ------------------------------
    Juliano Garcia
    Suport Analyst
    Coamo -Coop. Agropecuaria Mouraoense
    Campo Mourão BR
    ------------------------------



  • 6.  RE: Ternary Operator?

    Posted 08-17-2022 02:23

    Hi Juliano,

    Happy to have helped you!

    BTW...a real ternary operator would have a larger perimeter! The user defined function I've provided accept only strings while a real ternary operator would accept any data type for value1 and value2 (numbers, dates, ...).

    IMHO the request for a real ternary operator remains a nice to have wish.

    Gianni



    ------------------------------
    Gianni Sandigliano
    IT
    ------------------------------