xHarbour Reference Documentation > Function Reference xHarbour Developers Network  

AAdd()

Adds one element to the end of an array.

Syntax

AAdd( <aArray>, <xValue> ) --> xValue

Arguments

<aArray>
A variable holding an array to add an element to.
<xValue>
An arbitrary value to add to <aArray>.

Return

The function returns the value added to the array.

Description

The AAdd() function increases the length of the array <aArray> by one element and assigns the value <xValue> to the new element. It is the last element of <aArray>.

AAdd() dynamically grows an array one element at a time. This is convenient when less than 100 elements should be added to <aArray>. To collect more elements in a loop, for example, it is recommended to dimension the array adequately or to grow multiple elements at a time using the ASize() function.

When <xValue> is of data type Array, a multi-dimensional array is created.

Info

See also:ADel(), AEval(), AFill(), AIns(), ASize()
Category: Array functions
Source:vm\arrayshb.c
LIB:xhb.lib
DLL:xhbdll.dll

Example

// This example adds 10 numbers to an array and displays a message
// after adding each element.

   PROCEDURE MAIN()
      LOCAL n, aArray := {}

      ? Len( aArray )                  // result: 0

      FOR n := 1 to 10
         AAdd( aArray, n )
         ? "Added value", n, "to the array."
      NEXT

      ? Len( aArray )                  // result: 10
   RETURN NIL

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe