KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Converting numeric values to boolean and boolean values to numbers
PRODUCT: 4D | VERSION: | PLATFORM:
Published On: March 25, 1999

Converting Numeric Values to Boolean values:

One way of testing if a number is a specific value is to execute the following code:

vNum;=1
If (vNum=1)
 vBoolean:=True
Else
 vBoolean:=False
End if

The result from executing the above code is vBoolean will equal True. A simpler way of testing the value of a number is:

vNum:=1
vBoolean:=(vNum=1)

The result from executing the above code is vBoolean will also equal True.

Converting Boolean Values to Numeric Values:

There is also a simple way of converting Boolean values to numbers using the Num function:

vBoolean:=True
vNum:=Num(vBoolean)

In this case Num(vBoolean) will return 1. And conversely if vBoolean is False, Num(vBoolean) will return 0.

vBoolean:=False
vNum:=Num(vBoolean)

Using a conversion in your database.

When 4D displays a Boolean value, it displays it as a checkbox. It takes more time to draw a picture, such as a checkbox, to the screen than text. A List Form which contains Boolean fields will draw faster when they are displayed as text instead of as checkboxes. The steps to do this are:

- Create a numeric variable, on the form, to display the format text.
- Create some code that converts the data. If this is for a List Form, it is best to limit when this code will be executed such as the On Display Detail form event. Such as:

`Object Method: vDisplayGender

C_LONGINT(vDisplayGender)

If (Form event=On DIsplay Detail)
 vDisplayGender:=Num([Personnel]vGender_
End if

- Give the variable a format such as:  Female;;Male

The result will be if the field has a value of True, it will display the word "Female" and when the value is False it will display the word "Male".