| xHarbour Reference Documentation > Function Reference |
![]() |
![]() |
![]() |
Fills an array with a constant value.
AFill( <aArray>, <expression>, [<nStart>], [<nCount>] ) --> aArray
The function returns a reference to <aArray>.
The array function AFill() traverses the passed array and assigns the value of <expression> to the specified number of elements, beginning at position <nStart>. The array is only traversed in its first dimension. Milti-dimensional arrays cannot be filled using AFill().
Note: <expression> is evaluated only once, i.e. all elements are assigned the same value. If the value is of complex data type that is a referenceto to a value (e.g. Array or Object), all elements contain the same reference to the same value.
| See also: | AAdd(), AEval(), AIns(), DbStruct(), Directory() |
| Category: | Array functions |
| Source: | vm/arrayshb.c |
| LIB: | xhb.lib |
| DLL: | xhbdll.dll |
// The example creates an array filled with "0" and demonstrates the
// effect of using a complex data type (Array) to fill an array with.
PROCEDURE Main()
LOCAL aArray[3]
// using a simple data type
AFill( aArray, "A" )
? aArray[1], aArray[2], aArray[3] // result: A A A
// using a complex data type
AFill( aArray, { "A", "B" } )
? aArray[1,1], aArray[1,2] // result: A B
? aArray[2,1], aArray[2,2] // result: A B
? aArray[3,1], aArray[3,2] // result: A B
// changing one element
aArray[3,2] := "DON'T"
? aArray[1,1], aArray[1,2] // result: A DON'T
? aArray[2,1], aArray[2,2] // result: A DON'T
? aArray[3,1], aArray[3,2] // result: A DON'T
// One assignment changes all elements
// since aArray contains three times
// the same array reference.
RETURN
http://www.xHarbour.com