KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: The BOOLEAN ARRAY FROM SET command
PRODUCT: 4D | VERSION: 6.5 | PLATFORM: Mac & Win
Published On: January 12, 2001
Your current browser may not allow you to download the asset. We recommend Mozilla Firefox or Google Chrome.
Log In

The "BOOLEAN ARRAY FROM SET" command introduced in 4D v6.5 can help you handle records in powerful ways. For example, you can use it to manipulate the current selection of records in an output form.

The command requires two parameters. In the first parameter, you specify a Boolean array. In the second parameter, you specify a set. The command will then build a Boolean array with entries showing whether or not each record is included in the set.

To take advantage of this command's power, you need to understand exactly what's in the array. The number of elements in the array will be equal to the highest record number used in the table the specified set belongs to. For example, suppose you create a new database, enter ten records in it, put them all into a set, then run the BOOLEAN ARRAY FROM SET command. The Boolean array it creates will have nine elements in it, because the range of record numbers you have in the table is 0 through 9. (In addition to the nine elements, 4D arrays also have an element 0, which makes for an actual total of ten elements.) The record number of the table's first record is 0, and the record number of the last record is 9.) Because all the records are in the set, elements 0 through 9 of the Boolean array are True.

Now let's suppose you delete the first five records in the table, put all the remaining records in the table into a set, then run the BOOLEAN ARRAY FROM SET command. The Boolean array it creates will still have elements ranging from 0 through 9. The number of elements in the array will always be one less than the highest record number that has been used in the table. The size of the Boolean array does NOT necessarily correspond to the number of records in the table. In this example, elements 0 through 4 of the array will be False, and elements 5 through 9 will be True.

Because all the elements of the array correspond to record numbers, it is easy to find out if a specific record number is in the set. Using our last example, if you wanted to know if the record whose record number is 6 is in the set, all you have to do is check the value of the 6th element of the array.

The 4D Language Reference contains more information about record numbers: