9 Replies Latest reply: Aug 8, 2011 12:21 PM by John Witherspoon RSS

    Negation in Expression

    Simon Haugbølle

      Hi

       

      I just want to ask if it is possible to do negation using an expression. I want to negate a boolean variable by clicking a button. I am using an If expression now, so I am really good without negation, but I just want to know if I am missing something. I should say I would rather not write a script...

       

      I have tried !, ~, Not()...

       

      Also, has anyone seen an option of the button object that makes the button a toggle button?

       

      Thanks!

       

      Simon

        • Re: Negation in Expression
          John Witherspoon

          NOT is negation.  if(not true(),'A','B') would return 'B'.

           

          I'm not sure that's what you're asking for, though.  It sounds like you have a boolean expression somewhere already.  Based on a toggle button, you either want that expression, or the NOT of that expression.

           

          For boolean, false()=0, true()=-1, but any non-zero is also considered true.  One way to negate a boolean, then, is to add 1 and mod 2.  Mod(true()+1,2) = 0 = false.  Mod(false()+1,2) = 1 = true.  We can also do this with our "new" value of true, mod(1+1,2) = false.  So to negate, we want to add 1.  To leave alone, we want to add 0.  If we had a toggle button that toggled between 0 and 1, it would toggle between negating and not.  And we've already seen how to swap between zero and 1, just add 1 and mod 2.  So then our toggle button can be a variable, and every time you press the button, add one and mod 2 to the variable.  Then for your condition, just add the variable.

           

          See attached.  I really don't know if that's what you wanted, though.

            • Re: Negation in Expression
              Simon Haugbølle

              Hi John

               

              That is one thorough solution...

               

              Now, I'm doing this on the button (setting vEnableLineBreak)

              =If(vEnableLineBreak=False(), True(), False())

               

              Your Mod solution is pretty close to what I wanted... Although I was hoping for a single function, so I could just write something like

              =Not(vEnableLineBreak)

               

              PS: I love how you switch the color. A brilliant solution. hehe

               

              // Simon

                • Re: Negation in Expression
                  John Witherspoon

                  Well, on the button itself, you can just do this:

                   

                  =not vEnableLineBreak

                   

                  It'll then switch between 0 and -1, and have the same effect on the if() expressions.  I don't see how to simplify the if() expressions, though, and was just being consistent between the button and the expressions on my negation approach.  Perhaps simplicity is better than consistency here, and definitely if ALL you wanted was that button, I'd got with the NOT approach.

              • Negation in Expression
                Rob Wunderlich

                You can toggle a boolean variable with

                 

                =NOT varname

                 

                -Rob