Function AAdd() Foundation

Enlarges an array by one element.

Syntax
AAdd( <aArray>, <Expression>, [<nElement>] ) --> xValue
Parameters
<aArray>
<aArray> is the array to which a new element is added.
<Expression>
<Expression> determines the value assigned to the new element. <Expression> can be a constant, a variable, or a function call. The argument <Expression> is not optional. <Expression> may have any data type.
<nElement>
The optional argument <nElement> specifies the position within the array of the element to which the new value is assigned. If <nElement> is not specified, the value is assigned to the last element.
Return

The return value of AAdd() is the value of <Expression>.

Description

The array function AAdd() adds one element to an existing array. The new element is the last element in the array or the element at the position <nElement>. The new element has the value associated with <Expression>. The length of the array is not limited in Xbase++.

AAdd() is used to manage dynamic lists. The function ASize() has a similar purpose, allowing the size of any array to be set. The advantage of AAdd() is that the value <Expression> is also assigned to the new element.

When the value of <Expression> is an array, the new element in <aArray> contains a reference to the array specified in <Expression>. <aArray> then becomes a multi-dimensional array.

Examples
Enlarge arrays dynamically

// The example demonstrates the use of AAdd() with various 
// data types. In the first series, elements are added at the end 
// of the array, in the second elements are inserted into the 
// array. 

PROCEDURE Main 
   LOCAL aArray := {}           // aArray is an empty array 

   AAdd( aArray, .T.)           // aArray is {.T.} 
   AAdd( aArray, "A")           // aArray is {.T., "A"} 
   AAdd( aArray, Asc("A") )     // aArray is {.T., "A", 65} 
   AAdd( aArray, NIL )          // aArray is {.T., "A", 65, NIL} 
   AAdd( aArray, {"NAME","C",20,0} ) 
                       // aArray is 
                       // {.T., "A", 65, NIL, {"NAME","C",20,0} } 

   aArray := {} 

   AAdd( aArray, .T.)           // aArray is {.T.} 
   AAdd( aArray, "A",1 )        // aArray is {"A",.T.} 
   AAdd( aArray, Asc("A"), 2 )  // aArray is {"A", 65,.T.} 

RETURN 
Feedback

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.