[<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 Execute a code block for each element in an array

     AEVAL(<aArray>, <bBlock>,
        [<nStart>], [<nCount>]) --> aArray


     <aArray> is the array to traverse.

     <bBlock> is a code block to execute for each element encountered.

     <nStart> is the starting element.  If not specified, the default is
     element one.

     <nCount> is the number of elements to process from <nStart>.  If not
     specified, the default is all elements to the end of the array.


     AEVAL() returns a reference to <aArray>.


     AEVAL() is an array function that evaluates a code block once for each
     element of an array, passing the element value and the element index as
     block parameters.  The return value of the block is ignored.  All
     elements in <aArray> are processed unless either the <nStart> or the
     <nCount> argument is specified.

     AEVAL() makes no assumptions about the contents of the array elements it
     is passing to the block.  It is assumed that the supplied block knows
     what type of data will be in each element.

     AEVAL() is similar to DBEVAL() which applies a block to each record of a
     database file.  Like DBEVAL(), AEVAL() can be used as a primitive for
     the construction of iteration commands for both simple and complex array

     Refer to the Code Blocks section in the "Basic Concepts" chapter of the
     Programming and Utilities Guide for more information on the theory and
     syntax of code blocks.


     .  This example uses AEVAL() to display an array of file names
        and file sizes returned from the DIRECTORY() function:

        #include "Directry.ch"
        LOCAL aFiles := DIRECTORY("*.dbf"), nTotal := 0
           { | aDbfFile |;
              QOUT(PADR(aDbfFile[F_NAME], 10), aDbfFile[F_SIZE]),;
              nTotal += aDbfFile[F_SIZE]);
           } )
        ? "Total Bytes:", nTotal

     .  This example uses AEVAL() to build a list consisting of
        selected items from a multidimensional array:

        #include "Directry.ch"
        LOCAL aFiles := DIRECTORY("*.dbf"), aNames := {}
           { | file | AADD(aNames, file[F_NAME]) };

     .  This example changes the contents of the array element
        depending on a condition.  Notice the use of the codeblock

        LOCAL aArray[6]
        {|cValue,nIndex| IF(cValue == "old",;
                          aArray[nIndex] := "new",)})

 Files   Library is CLIPPER.LIB.

See Also: DBEVAL() EVAL() QOUT()
This page created by ng2html v1.05, the Norton guide to HTML conversion utility. Written by Dave Pearson