In Fahrenheit 451 by legendary author Ray Bradbury, getting caught with a single book in your home could result in a visit from the fire department- to burn you house, and books within, to the ground. Protagonist and fireman Guy Montag steals a book, almost unwittingly, and soon finds that he must make a choice between knowledge and ignorance. A choice that could cost him his very life.
FileMaker’s Choose function would have been utterly useless to Montag, but it’s still a really awesome book.
To use Choose you must start with a math problem followed by a list of results. The function will choose the result that corresponds to the math problem’s answer.
In the above example, our math problem is 2+2. FileMaker first evaluates that to determine the value 4. Now it traverses the list of results starting with result zero. It skips each non-matching result until it gets to result 4. Result 4, matching the answer to the math problem, becomes the chosen result and the function returns the word “four”.
As functions go Choose is dead simple, but there are some things to watch out for.
- The first result is result zero. Even if you never expect a result less than 1, you must provide something for result zero. The example below handles this situation using a pair of quotation marks with nothing between them- a standard way to represent a null result in FileMaker.
- Choose doesn’t work with negative numbers. You can get around this by wrapping your whole math problem in an Abs() function which gives you the absolute (i.e. non-negative) value of the math problem’s result.
- Choose ignores fractional values. When comparing the math problem’s answer to the list of possible results, Choose disregards everything to the right of the decimal point. Whether your math problem result is 1, 1.3, or 1.999, Choose is going to select Result 1 as your result.
One practical application of Choose is displaying a different message based on the current day of the week. The DayOfWeek function returns a number from 1 to 7 based on the date in its parameter. DayOfWeek ( Get ( CurrentDate ) ) will tell us the number of the current day. From there FileMaker can choose which message to display.
You might not see a lot occasions for incorporating Choose into your calculations, but when the need arises you’ll find that having Choose in your development toolbox will save you a lot of time and effort. For more about heart-wrenching life and death choices, visit your local library.