xHarbour Reference Documentation > Function Reference xHarbour Developers Network  

AFill()

Fills an array with a constant value.

Syntax

AFill( <aArray>, <expression>, [<nStart>], [<nCount>] ) --> aArray

Arguments

<aArray>
This is the variable holding the array to fill with a value.
<expression>
An expression yielding a value of arbitrary data type. The expression is evaluated once and the resulting value is assigned to each element of <aArray>.
<nStart>
This is a numeric expression indicating the first element in the array to fill. It defaults to 1.
<nCount>
A numeric expression specifying the number of elements to fill. It defaults to 1+Len(<aArray>)-<nStart>.

Return

The function returns a reference to <aArray>.

Description

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.

Info

See also:AAdd(), AEval(), AIns(), DbStruct(), Directory()
Category: Array functions
Source:vm/arrayshb.c
LIB:xhb.lib
DLL:xhbdll.dll

Example

// 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

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