Click or drag to resize

VoDbEval Function

X#
Evaluate a code block for each record that matches a specified scope and/or condition.

Namespace:  XSharp.RT
Assembly:  XSharp.RT (in XSharp.RT.dll) Version: 2.21
Syntax
 FUNCTION VoDbEval(
	cbExecute AS USUAL,
	cbForCondition AS USUAL,
	cbWhileCondition AS USUAL,
	nNext AS USUAL,
	nRecord AS USUAL,
	lRest AS LOGIC
) AS LOGIC
Request Example View Source

Parameters

cbExecute
Type: Usual
The code block to execute for each record that matches the scope and conditions.
cbForCondition
Type: Usual
A code block that defines a condition that each record within the scope must meet in order to be processed.
cbWhileCondition
Type: Usual
A code block that defines another condition that each record must meet in order to be processed. As soon as a record is encountered that causes the condition to fail, the operation terminates.
If no scope is specified, cbWhileCondition changes the default scope to lRest.
You define the scope using one of these three, mutually exclusive arguments.
The default is all records.
nNext
Type: Usual
The number of records to process, starting at nRecord. Specify 0 to ignore this argument.
nRecord
Type: Usual
A single record number to process. Specify 0 to ignore this argument.
lRest
Type: Logic
TRUE processes only records from nStart to the end of the file. FALSE processes all records.

Return Value

Type: Logic
TRUE if successful; otherwise, FALSE.
Remarks
Tip Tip
The nNext, nRecord, and lRest arguments are mutually exclusive. You should not pass all three of them. And if you pass the cbWhile argument then this also controls the scope behavior.
VODBEval() is like DBEval() but is strongly typed.
This function, however, does not call the error handler and will not, therefore, produce a runtime error message or create an error object if it fails. Thus, it may be important to check the return value to determine if the function succeeded.
The global structure, StrucErrInfo, will contain needed information regarding any error that occurs. See DBEval() for more information.
Examples
This example uses VODBEval() to implement Count(), a function that counts the number of records in a work area matching a specified scope.
The scope is passed as an array to Count().
A set of constants defines the elements of the scope array:
X#
 1// Scope attribute constants
 2DEFINE FOR_COND        :=    1    AS SHORTINT
 3DEFINE WHILE_COND        :=    2    AS SHORTINT
 4DEFINE NEXT_SCOPE        :=    3    AS SHORTINT
 5DEFINE REC_SCOPE        :=    4    AS SHORTINT
 6DEFINE REST_SCOPE        :=    5    AS SHORTINT
 7DEFINE SCOPE_ELEMENTS    :=    5    AS SHORTINT
 8FUNCTION Start()
 9    // Create a scope and count records using it
10    LOCAL mySet[SCOPE_ELEMENTS]
11    LOCAL myCount AS LONGINT
12    USE customer NEW
13    mySet[FOR_COND] := {||customer = "Smith"}
14    mySet[WHILE_COND] := {||zip > "90000"}
15    mySet[REST_SCOPE] := FALSE
16    // Every record (ALL)
17    myCount := Count(mySet)
18    RETURN TRUE
19FUNCTION Count(aScope) AS LONGINT
20    LOCAL nCount := 0 AS LONGINT
21    VODBEval({|| nCount++},;
22        aScope[FOR_COND],;
23        aScope[WHILE_COND],;
24        aScope[NEXT_SCOPE],;
25        aScope[REC_SCOPE],;
26        aScope[REST_SCOPE])
27    RETURN nCount
See Also