aEVAL

This forum is for eXpress++ general support.
Post Reply
Message
Author
User avatar
unixkd
Posts: 579
Joined: Thu Feb 11, 2010 1:39 pm

aEVAL

#1 Post by unixkd »

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.

User avatar
rdonnay
Site Admin
Posts: 4813
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: aEVAL

#2 Post by rdonnay »

What is <lAssign> for?
The eXpress train is coming - and it has more cars.

User avatar
rdonnay
Site Admin
Posts: 4813
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: aEVAL

#3 Post by rdonnay »

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.

User avatar
unixkd
Posts: 579
Joined: Thu Feb 11, 2010 1:39 pm

Re: aEVAL

#4 Post by unixkd »

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

User avatar
rdonnay
Site Admin
Posts: 4813
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: aEVAL

#5 Post by rdonnay »

lAssign is as used in aEval() function of Xbase++
I never noticed that parameter before.
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.

User avatar
unixkd
Posts: 579
Joined: Thu Feb 11, 2010 1:39 pm

Re: aEVAL

#6 Post by unixkd »

Thanks Roger

That is excellent. Will be a good addition to eXpress++ next release.

Joe

Post Reply