KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Create small sets of selections from a large record selection
PRODUCT: 4D | VERSION: 2004 | PLATFORM: Mac & Win
Published On: December 19, 2005
Your current browser may not allow you to download the asset. We recommend Mozilla Firefox or Google Chrome.
Log In

There are a number of ways to create a partial selection of records without losing the current selection. One way is to generate sets containing the partial selections, which can be done using this pair of commands:

- SELECTION RANGE TO ARRAY allows the developer to build an array of record numbers based on a defined range (start record to end record) in a selection.

- CREATE SET FROM ARRAY can generate a set of records using an array of absolute record numbers.

For example the following code will generate a dynamic number of sets, each with 50 records, until all records in the full selection are in a set.

C_STRING(80;$setNamePrefix)

C_LONGINT($SetNum;$MaxSetSize;$SelSize)

$setNamePrefix:="$Set"

$MaxSetSize:=50  ` number of records per set

$SelSize:=Records in selection([Table])  ` entire selection

For ($setNum;1;1+(($SelSize-1)\$MaxSetSize))

  ` Load the record numbers into temp array

ARRAY LONGINT($recNumAr;0)

SELECTION RANGE TO ARRAY(1+($MaxSetSize*($setNum-1));$MaxSetSize*$setNum;[Table];$recNumAr)

  ` store record numbers into a set

CREATE SET FROM ARRAY([Table];$recNumAr;$setNamePrefix+String($setNum))

End for

For ($setNum;1;1+(($SelSize-1)\$MaxSetSize))

If (Records in set("$set"+String($setNum))>0)

  `something is in the set, act upon it



End if

  `clean-up

CLEAR SET("$set"+String($setNum))

End for