Click or drag to resize

AEvalOld Function (Array, ICodeblock, Usual, Usual)

Execute a code block for each element in an array.

Namespace:  XSharp.RT
Assembly:  XSharp.RT (in XSharp.RT.dll) Version: 2.4a
Syntax
 FUNCTION AEvalOld(
	aArray AS ARRAY,
	cbBlock AS ICodeblock,
	nStart AS USUAL,
	nCount AS USUAL
) AS ARRAY
View Source

Parameters

aArray
Type: Array
The array to traverse.
cbBlock
Type: ICodeblock
The code block to execute.
nStart
Type: Usual
The starting element
A negative value starts from the end.
If <nCount> is positive, the default value is 1; if <nCount> is negative, the default value is the length of the array.
nCount
Type: Usual
The number of elements to process from <nStart>.
A negative value starts from the end.
The default is all elements to the end of the array.

Return Value

Type: Array
A reference to <aArray>.
The return value of the code block is ignored.
To assign the return value of the code block to each element in the array, use the AEvalA() function.
Remarks
AEvalOld() passes the element value and the element index as arguments.
AEvalOld() makes no assumptions about the contents of the array elements it is passing.
It is assumed that the supplied code block knows what type of data will be in each element. AEvalOld() is similar to DBEval() which executes code for each record of a database file.
Like DBEval(), AEvalOld() can be used as a primitive for the construction of iteration commands for both simple and complex array structures.
Tip Tip
In Visual Objects and Vulcan.Net 2 different functions were introduced: AEval() and AEvalOld(). The difference between these functions was that AEval() was only calling the codeblock with one parameter (the element in the array), where AEvalOld() was also passing in a second parameter (the array index). Inside X# this difference no longer exists. So AEval() and AEvalOld() are doing the same thing in X#.
Examples
This example uses AEvalOld() to display an array of file names and file sizes returned from the Directory() function:
X#
1LOCAL aFiles := Directory("*.dbf")
2LOCAL nTotal := 0
3AEvalOld(aFiles, {| aDBFFile | QOut(PadR(aDBFFile[F_NAME], 10), ;
4        aDBFFile[F_SIZE]), aDBFFile[F_SIZE]), nTotal += aDBFFile[F_SIZE]})
5? "Total Bytes:", nTotal
This next example changes the contents of the array element depending on a condition.
If the condition is false, array elements are merely displayed.
Notice the use of the code block arguments:
X#
1LOCAL aArray[6]
2AFill      (aArray, "old")
3AEvalOld   (aArray, {|cValue, nIndex| IF(cValue == "old",;
4ArrayPut (aArray, nIndex,"new"),QOut(cValue))})
See Also