Functions and Directives

Function AFill() Foundation

Fills elements in an array with a single value.

AFill( <aArray>, [<Expression>], [<nStart>], [<nCount>] ) --> aArray
<aArray> is the array which is filled.
<Expression> is any expression whose value is assigned to each array element. The default value is NIL.
<nStart> is a numeric value specifying the first element of the array <aArray> which is assigned the value of <Expression>. The default value is 1.
<nCount> is a numeric value specifying the number of elements, starting with <nStart>, to which the value is assigned. If <nCount> is missing, assignment occurs for all elements from <nStart> to the last element of <aArray>.

The return value of AFill() is a reference to <aArray>.


The array function AFill() fills an array with a single value. The value can be of any data type. If the value is an object or an array, all the elements of the filled array contain the same reference to the object or subarray. The function assigns the value only to the elements of the first dimension. Multidimensional arrays cannot be filled with AFill().

Fill an array with a value using AFill()
// In the example, two calls to AFill() are shown. The 
// first example, where the starting position is passed, only 
// fills two elements. The second call assigns a value to 
// all elements of the array. 

   LOCAL aArray[5]           // aArray is: {NIL,NIL,NIL,NIL,NIL} 

   AFill( aArray,.T., 3, 2 ) // aArray is: {NIL,NIL,.T.,.T.,NIL} 

   AFill( aArray,.F.)        // aArray is: {.F.,.F.,.F.,.F.,.F.} 

   AFill( aArray )           // aArray is: {NIL,NIL,NIL,NIL,NIL} 


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.