Log In    |    Knowledge Base    |    4D Home
Tech Tip: Converting numeric values to boolean and boolean values to numbers
Published On: March 25, 1999
Your current browser may not allow you to download the asset. We recommend Mozilla Firefox or Google Chrome.
Log In

Converting Numeric Values to Boolean values:

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

If (vNum=1)
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:


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:


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


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


If (Form event=On DIsplay Detail)
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".