Tag Archives: Eval
FieldWBlock()
FIELDWBLOCK()
Return a sets/gets code block for field in a given work area
Syntax
FIELDWBLOCK( <cFieldName>, <nWorkArea> ) --> bFieldBlock
Arguments
<cFieldName> is a string that contain the field name.
<nWorkArea> is the work area number in which <cFieldName> exist.
Returns
FIELDWBLOCK() return a code block that when evaluate could retrieve field value or assigning a new value for a field in a given work area. If <cFieldName> is not specified or from type other than character, or if <nWorkArea> is not specified or is not numeric FIELDWBLOCK() return NIL.
Description
FIELDWBLOCK() return a code block that sets/gets the value of field from a given work area. When this code block is evaluated without any parameters passed then it returns the current value of the given field. If the code block is evaluated with a parameter, than its value is used to set a new value to the field, this value is also return by the block. If the block is evaluate and there is no field with the name <cFieldName> in work area number <nWorkArea>, the code block return NIL.
Examples
LOCAL bField // this block work on the field "name" that exist on work area 2 bFiled := FIELDBLOCK( "name", 2 ) // open a file named One in work area 1 // that have a field named "name" SELECT 1 USE one // open a file named Two in work area 2 // it also have a field named "name" SELECT 2 USE two SELECT 1 ? "Original names: ", One->name, Two->name ? "Name value for file Two :", EVAL( bField ) EVAL( bField, "Two has new name" ) ? "and now: ", One->name, Two->name
Compliance
If the block is evaluate and there is no field with the name <cFieldName> in the given work area, the code block return NIL.
CA-Cl*pper would raise BASE/1003 error if the field does not exist.
Files
Library is rtl
Seealso
EVAL(), FIELDBLOCK(), MEMVARBLOCK()
FieldBlock()
FIELDBLOCK()
Return a code block that sets/gets a value for a given field
Syntax
FIELDBLOCK( <cFieldName> ) --> bFieldBlock
Arguments
<cFieldName> is a string that contain the field name.
Returns
FIELDBLOCK() return a code block that when evaluate could retrieve a field value or assigning a new value to the field. If <cFieldName> is not specified or from type other than character, FIELDBLOCK() return NIL.
Description
FIELDBLOCK() return a code block that sets/gets the value of field. When this code block is evaluated without any parameters passed then it returns the current value of the given field. If the code block is evaluated with a parameter, than its value is used to set a new value to the field, this value is also return by the block. If the block is evaluate and there is no field with the name <cFieldName> in the current work area, the code block return NIL.
Note that FIELDBLOCK() works on the current work area, if you need a specific work area code block use FIELDWBLOCK() instead.
Examples
// open a file named Test that have a field named "name" LOCAL bField bFiled := FIELDBLOCK( "name" ) USE Test ? "Original value of field 'name' :", EVAL( bField ) EVAL( bField, "Mr X new name" ) ? "New value for the field 'name' :", EVAL( bField )
Compliance
If the block is evaluate and there is no field with the name <cFieldName> in the current work area, the code block return NIL.
CA-Cl*pper would raise BASE/1003 error if the field does not exist.
Files
Library is rtl
Seealso
EVAL(), FIELDWBLOCK(), MEMVARBLOCK()
Harbour Error Handling Functions
dbEval()
DBEVAL()
Performs a code block operation on the current Database
Syntax
DBEVAL( <bBlock>, [<bFor>], [<bWhile>], [<nNext>], [<nRecord>], [<lRest>] ) --> NIL
Arguments
<bBlock> Operation that is to be performed
<bFor> Code block for the For condition
<bWhile> Code block for the WHILE condition
<nNext> Number of NEXT records to process
<nRecord> Record number to work on exactly
<lRest> Toggle to rewind record pointer
Returns
DBEVAL() always returns NIL
Description
Performs a code block operation on the current Database
Examples
PROCEDURE Main() LOCAL nCount USE test dbGoto( 4 ) ? RecNo() COUNT TO nCount ? RecNo(), nCount COUNT TO nCount NEXT 10 ? RecNo(), nCount RETURN
Compliance
Clipper
Files
Library is rdd
Seealso
EVAL()
Eval()
EVAL()
Evaluate a code block
Syntax
EVAL( <bBlock> [, <xVal> [,...]]) --> xExpression
Arguments
<bBlock> Code block expression to be evaluated
<xVal> Argument to be passed to the code block expression
<xVal…> Argument list to be passed to the code block expression
Returns
<xExpression> The result of the evaluated code block
Description
This function evaluates the code bloc expressed as <bBlock> and returns its evaluated value. If their are multiple expressions within the code block, the last expression will be value of this function.
If the code block requires parameters to be passed to it, they are specified in the parameter list <xVal> and following. Each parameter is separated by a comma within the expression list.
Examples
PROCEDURE Main() LOCAL bBlock := {|| NIL } ? Eval( 1 ) ? Eval( @bBlock ) ? Eval( {| p1 | p1 }, "A", "B" ) ? Eval( {| p1, p2 | p1 + p2 }, "A", "B" ) ? Eval( {| p1, p2, p3 | p1 }, "A", "B" ) RETURN
Tests
See examples
Compliance
Clipper
Platforms
All
Files
Library is vm
Seealso
AEVAL(), DBEVAL()
ASort()
ASORT()
Sort an array
Syntax
ASORT( <aArray>, [<nStart>], [<nCount>], [<bSort>] ) --> aArray
Arguments
<aArray> Array to be sorted.
<nStart> The first element to start the sort from, default is 1.
<nCount> Number of elements starting from <nStart> to sort, default is all elements.
<bSort> Code block for sorting order, default is ascending order {| x, y | x < y }. The code block should accept two parameters and must return .T. if the sort is in order, .F. if not.
Returns
<aArray> reference to the now sorted <aArray> or NIL if the passed <aArray> is not an array.
Description
ASORT() sort all or part of a given array. If <bSort> is omitted, the function expect <aArray> to be one dimensional array containing single data type (one of: Character, Date, Logical, Numeric) and sort this array in ascending order: Character are sorted by their ASCII value, Dates are sorted chronologically, Logical put .F. values before .T., Numeric are sorted by their value.
If <bSort> is specified, it is used to handle the sorting order. With each time the block is evaluate, two array elements are passed to the code block, and <bSort> must return a logical value that state if those elements are in order (.T.) or not (.F.). Using this block you can sort multidimensional array, descending orders or even (but why would you want to do that) sort array that contain different data type.
Examples
// sort numeric values in ascending order ASort( { 3, 1, 4, 42, 5, 9 } ) // result: { 1, 3, 4, 5, 9, 42 } // sort character strings in descending lexical order aKeys := { "Ctrl", "Alt", "Delete" } bSort := {| x, y | Upper( x ) > Upper( y ) } ASort( aKeys,,, bSort ) // result: { "Delete", "Ctrl", "Alt" } // sort two-dimensional array according to 2nd element of each pair aPair := { { "Sun", 8 }, { "Mon", 1 }, { "Tue", 57 }, { "Wed", -6 } } ASort( aPair,,, {| x, y | x[ 2 ] < y[ 2 ] } ) // result: { { "Wed", -6 }, { "Mon", 1 }, { "Sun", 8 }, { "Tue", 57 } }
Compliance
Clipper (arrayblock)
Files
Library is vm
Seealso
ASCAN(), EVAL(), SORT
AEval()
AEVAL()
Evaluates the subscript element of an array
Syntax
AEVAL(<aArray>, <bBlock>, [<nStart>], [<nCount>]) --> aArray
Arguments
<aArray> Is the array to be evaluated.
<bBlock> Is a code block to evaluate for each element processed.
<nStart> The beginning array element index to evaluate.
<nCount> The number of elements to process.
Returns
<aArray> an array pointer reference.
Description
This function will evaluate and process the subscript elements in <aArray>. A code block passed as <bBlock> defines the operation to be executed on each element of the array. All elements in <aArray> will be evaluated unless specified by a beginning subscript position in <nStart> for <nCount> elements.
Two parameters are passed to the code block <bBlock>. The individual elements in an array are the first parameter and the subscript position is the second.
AEVAL() does not replace a FOR…NEXT loop for processing arrays. If an array is an autonomous unit, AEVAL() is appropriate. If the array is to be altered or if elements are to be reevaluated, a FOR…NEXT loop is more appropriate.
Compliance
Clipper
Files
Library is vm
Seealso
EVAL(), DBEVAL()
SP_WORKBLOCK
WORKBLOCK() Short: ------ WORKBLOCK() Returns a set-get block for field named in an expression Returns: -------- <bBlock> => a set-get block Syntax: ------- WORKBLOCK(cExpress) Description: ------------ Determines the work area and field name in <cExpress> and returns a FIELDWBLOCK() created block for it. Examples: --------- cExpr := "CUSTOMER->LNAME" bExpr := WORKBLOCK(cExpr) ?eval(bExpr) // displays value ?eval(bExpr,"SMITH") // sets new value Source: ------- S_FIELDS.PRG
SP_SACHOICE
SACHOICE() Short: ------ SACHOICE() Achoice replacement, uses TBROWSE, codeblock Returns: -------- <nSelection> => selection, 0 if none Syntax: ------- SACHOICE(nTop,nLeft,nBottom,nRight,aOptions,[bKeyBlock],[nStart],[@nRow],; [nMRow, nMCol],[bMouse]) Description: ------------ This semi-replaces ACHOICE() by using TBROWSE instead, and by accepting an exception codeblock instead of a user defined function. <nTop,nLeft,nBottom,nRight> are the dimensions. <aOptions> is the array. It need not be of type Character. First-letter presses go to the next matching letter of the next character-type element. Up/down/home/end/pageup/pagedown are used to position the cursor. ENTER returns the current selection. Escape returns 0. The screen is not saved and restored. This is a building block function, like ACHOICE(), so save and restore the screen, draw a box around it, etc, as you would ACHOICE(). [bKeyBlock] a codeblock which will be executed if an exception key is received (any key not otherwise meaningful). The codeblock will be evaluated and will be passed: 1. current element # 2. exception key value 3. the tbrowse object as parameters. [nStart] is an optional starting element. Default is 1. [@nRow] is an optional starting row. Default is 1. Pass by reference to retain value between calls. [nMRow, nMCol] (new in 3.5) Directs sachoice() to draw the "[.][.]" for mouse up/down at nMrow, nMCol, and to be aware of mouse clicks on these buttons. (the screen under the arrows is saved/restored) [bMouse] is a codeblock to evaluate mouse clicks other than those meaningful to sachoice(). The codeblock is evaluated as follows: eval(bMouse,mouserow, mousecolumn) Examples: --------- USE CUSTOMER aFlds := afieldsx() bExcept := {|e,k|msg("You pressed ",str(k))} ?SACHOICE(10,10,20,12,aFlds,bExcept) //to retain element and position between calls nSelect := 1 nRow := 1 aMeals := {"Pizza","Chicken","Chinese"} while nSelect > 0 nSelect := sachoice(10,10,20,20,aMeals,nil,nSelect,@nRow) // code endif Notes: ------- This will be a lot easier to mouse-ize than ACHOICE. (or is that RAT-ify..) Source: ------- S_ACHOI.PRG