KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Three-state "Boolean" fields
PRODUCT: 4D | VERSION: | PLATFORM: Mac & Win
Published On: July 10, 2000

Sometimes you'll find you have a piece of data you want to store that's almost like a Boolean, except you need to have three states rather than two. Perhaps:


  • Yes
  • No
  • Unknown

The solution is to use an Integer field, and display it with a custom format, such as:

"+;-;?"

This format has three parameters, separated by semicolons:


  • The first parameter specifies the formatting to be applied to positive numbers. This example uses a plus sign.
  • The second parameter specifies the formatting to be applied to negative numbers. This example uses a minus sign.
  • The third parameter specifies the formatting for zero. This example uses a question mark.

    With this display format, if the field holds a positive number, it will display as a plus sign. If it holds a negative number, it will display as a minus sign. And if it holds zero, it will display a question mark, to indicate that the status is unknown.

    Here's another example. You could use the display format ">;>; " for a scheduler application. This way, if the field holds a positive number, it will display as a double greater-than sign (ASCII 200). If it holds a negative number, it will display as a single greater-than sign (ASCII 62). And if it holds zero, it will display a question mark, to indicate that the status is unknown. You can use this to format a column in an output form: if the record displays a space, that means it hasn't been scheduled. If the record displays a greater-than sign, that means it's been marked as an item to do. And if the record displays a double greater-than sign, that indicates the activity has been completed.

    Due to 4D's implementation of Boolean and Integer fields, using an Integer field doesn't take up any more storage space than using a Boolean field. Both use two bytes.