KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Append an element to the end of an array
PRODUCT: 4D | VERSION: 2003 | PLATFORM: Mac & Win
Published On: April 8, 2004
Your current browser may not allow you to download the asset. We recommend Mozilla Firefox or Google Chrome.
Log In

Here's a simple macro that will generate code to insert an element to the end of an array.

<macro name="AppendItemToArray">
<text>
INSERT ELEMENT(<Selection/>;Size of Array(<Selection/>)+1)
<Selection/>{Size of Array(<Selection/>)}:=<caret/>
</text>
</macro>

Add this macro to the end of Macros.xml (located in your active directory) before the </macros> closing tag.

Suppose your array is named $myArray. Simply type "$myArray" into the method editor and highlight it. Right-click over the selection and choose Insert Macros > AppendItemToArray. The macro will generate the following code:

INSERT ELEMENT($myArray;Size of array($myArray)+1)
$myArray{Size of array($myArray)}:=

and leave the cursor after the "=" symbol. Now you are ready to insert whatever value you want.