Hi All
Is it possible to extend aEval(...) like: Call it DC_AEval(...)
DC_AEval( <aArray>, <bBlock>, [<nStart>], [<nCount>], [<lAssign>],[<bFor>], [<bWhile>] ) --> aArray
Similar to DC_ForNext(...)
DC_ForNext ( <nStart>, ;
<nEnd>, ;
[<nStep>], ;
<bEval>, ;
[<bWhile>],;
[<bFor>] ) -> NIL
Thanks.
Joe.
aEVAL
Re: aEVAL
Here is the function you wanted, with the exception of lAssign.
Code: Select all
#INCLUDE "dcdialog.CH"
#INCLUDE "directry.CH"
FUNCTION Main()
LOCAL aDir, bEval, bFor, bWhile
aDir := Directory('C:\exp20\source\dclipx\*.*')
wtf aDir
bEval := {|a|Qout(Pad(a[F_NAME],20)),QQout(a[2])}
bFor := {|a|a[F_SIZE] > 2000 }
bWhile := {|a|a[F_SIZE] < 200000 }
DC_AEval( aDir, bEval,,,, bFor, bWhile)
wtf 'stop' pause
RETURN nil
* ------------
FUNCTION DC_Aeval( aArray, bBlock, nStart, nCount, lAssign, bFor, bWhile )
LOCAL nLen := Len(aArray), i, n := 0
DEFAULT nStart := 1, ;
nCount := nLen
FOR i := nStart TO nLen
IF n++ >= nCount
EXIT
ENDIF
IF !Empty(bWhile) .AND. !Eval(bWhile,aArray[i])
EXIT
ENDIF
IF Empty(bFor) .OR. Eval(bFor,aArray[i])
Eval( bBlock, aArray[i] )
ENDIF
NEXT
RETURN aArray
The eXpress train is coming - and it has more cars.
Re: aEVAL
Thanks Roger
lAssign is as used in aEval() function of Xbase++
The logical expression <lAssign> determines whether an assignment to the passed array element is permitted within the code block. If <lAssign> equals .T. (true), the array element is passed to the code block by reference. If an assignment to the first code block parameter is made, it is reflected in the corresponding array element.
Joe
lAssign is as used in aEval() function of Xbase++
The logical expression <lAssign> determines whether an assignment to the passed array element is permitted within the code block. If <lAssign> equals .T. (true), the array element is passed to the code block by reference. If an assignment to the first code block parameter is made, it is reflected in the corresponding array element.
Joe
Re: aEVAL
I never noticed that parameter before.lAssign is as used in aEval() function of Xbase++
Here is an updated DC_Aeval() function and a new test program.
DC_AEval() is first called to change the file names in the array to upper case.
DC_AEval() is then called to output the file names and sizes to the screen.
Code: Select all
#INCLUDE "dcdialog.CH"
#INCLUDE "directry.CH"
FUNCTION Main()
LOCAL aDir, bEval, bFor, bWhile
aDir := Directory('C:\expd20\source\dclipx\*.*')
bEval := {|a|a[F_NAME] := Upper(a[F_NAME])}
DC_AEval( aDir, bEval,,,.t., )
bEval := {|a|Qout(Pad(a[F_NAME],20)),QQout(a[2])}
bFor := {|a|a[F_SIZE] > 2000 }
bWhile := {|a|a[F_SIZE] < 200000 }
DC_AEval( aDir, bEval,,,, bFor, bWhile)
wait
RETURN nil
* ------------
FUNCTION DC_Aeval( aArray, bBlock, nStart, nCount, lAssign, bFor, bWhile )
LOCAL nLen := Len(aArray), i, n := 0
DEFAULT nStart := 1, ;
nCount := nLen, ;
lAssign := .f.
FOR i := nStart TO nLen
IF n++ >= nCount
EXIT
ENDIF
IF !Empty(bWhile) .AND. !Eval(bWhile,aArray[i])
EXIT
ENDIF
IF Empty(bFor) .OR. Eval(bFor,aArray[i])
IF lAssign
Eval( bBlock, @aArray[i] )
ELSE
Eval( bBlock, aArray[i] )
ENDIF
ENDIF
NEXT
RETURN aArray
The eXpress train is coming - and it has more cars.