Brian Dunning's FileMaker Custom Functions

Toggle ( state )

Simple toggle function, if the value passed is 1 the result is 0 and vice-versa

  Average rating: 4.6 (29 votes) Log in to vote

Ofir Gal   Ofir Gal
Gal Consultancy
http://www.gal.uk

Share on Facebook Share on Twitter

  Sample input:
Toggle ( 1 )
  Sample output:
0

  Function definition: (Copy & paste into FileMaker's Edit Custom Function window)

Simple switch toggle function, if the value passed is 1 the result is 0 and vice-versa. Doesn't use an if statement so should be faster. The only possible input and output values are 0 or 1.

 

Comments

Bob   Bob, Ct
Jan 14, 2010
How does this work, Is "State" a new FileMaker command I am not aware of yet?
 
Jonathan Mickelson   Jonathan Mickelson
Jan 14, 2010
Another pretty common way would be to use "not", ie:

not State

... kudos for working xor into a Filemaker Calc!!!

-----

To answer Bob: State is just the author's parameter naming. It could also have been written like:

Toggle ( boolean ) = where "boolean" is a boolean number, 0/1.
 
Ofir Gal   Ofir Gal, Gal Consultancy
Jan 15, 2010
Jonathan - I like your way even better. I guess 'xor 1' and 'not' are the same thing if effect.

Sorry if me calling the parameter 'state' is confusing. Maybe I should change it to 'switch' instead?
 
john R   john R, birmingham UK
Jan 29, 2010
Interesting method
I use Abs ( state - 1 )
to do the same thing...

Presumably no real efficiency differences.
 

Log in to post comments.

 

Note: these functions are not guaranteed or supported by BrianDunning.com. Please contact the individual developer with any questions or problems.

Under construction. Email me your wish list for improvements.