SUM

SUM

Sum numeric expressions and assign results to variables

Syntax

      SUM <nExp list> TO <idVar list>
            [<scope>] [WHILE <lCondition>] [FOR <lCondition>]

Arguments

<nExp list> is the list of numeric values to sum for each record processed.

TO <idVar list> identifies the receiving variables to be assigned assign the results of the sum. Variables that either do not exist or are not visible are created as private variables. <idVar list> must contain the same number of elements as <nExp list>.

<scope> is the portion of the current database file to SUM. The default scope is ALL records.

WHILE <lCondition> specifies the set of records meeting the condition from the current record until the condition fails.

FOR <lCondition> specifies the conditional set of records to SUM within the given scope.

Description

SUM is a database command that totals a series of numeric expressions for a range of records in the current work area and assigns the results to a series of variables. The variables specified in <idVar list> can be field, local, private, public, or static.

Note that the <nExp list> is required and not optional as it is in other dialects.

Examples

      .  This example illustrates the use of SUM:

      LOCAL nTotalPrice, nTotalAmount
      USE Sales NEW
      SUM Price * .10, Amount TO nTotalPrice, nTotalAmount
      //
      ? nTotalPrice               // Result: 151515.00
      ? nTotalAmount              // Result: 150675.00

Seealso

AVERAGE, DBEVAL(), TOTAL

DISPLAY

DISPLAY

Display records to the console

Syntax

      DISPLAY <exp list>
             [TO PRINTER] [TO FILE <xcFile>]
             [<scope>] [WHILE <lCondition>]
             [FOR <lCondition>] [OFF]

Arguments

<exp list> is the list of values to display for each record processed.

TO PRINTER echoes output to the printer.

TO FILE <xcFile> echoes output to the indicated file which can be specified either as a literal file name or as a character expression enclosed in parentheses. If an extension is not specified, .txt is added.

<scope> is the portion of the current database file to DISPLAY. The default is the current record, or NEXT 1. If a condition is specified, the scope becomes ALL.

WHILE <lCondition> specifies the set of records meeting the condition from the current record until the condition fails.

FOR <lCondition> specifies the conditional set of records to DISPLAY within the given scope.

OFF suppresses the display of the record number.

Description

DISPLAY is a database command that sequentially accesses records in the current work area, sending the results of the <exp list> to the console in a tabular format with each column separated by a space. The command does not display column headers or pause at predetermined intervals. DISPLAY is identical to LIST with the exception that its default scope is NEXT 1 rather than ALL.

When invoked, output is sent to the screen and optionally to the printer and/or a file. To suppress output to the screen while printing or echoing output to a file, SET CONSOLE OFF before the DISPLAY command line.

Notes

. Interrupting output: To let the user interrupt the processing of a DISPLAY command, using the INKEY() function, add a test for the interrupt key press to the FOR condition. See the example below. . Printer margin: Since DISPLAY is a console command, it honors the current SET MARGIN for output echoed to the printer.

Examples

      .  This example illustrates a simple DISPLAY, and a conditional
      DISPLAY to the printer:
      USE Sales NEW
      DISPLAY DATE(), TIME(), Branch
      DISPLAY Branch, Salesman FOR Amount > 500 TO PRINTER
      .  This example interrupts a DISPLAY using INKEY() to test
      whether the user pressed the Esc key:
      #define K_ESC  27
      USE Sales INDEX SalesMan NEW
      DISPLAY Branch, Salesman, Amount WHILE ;
         INKEY() != K_ESC

Seealso

DBEVAL(), INKEY(), LIST, SET MARGIN

DELETE

DELETE

Mark records for deletion

Syntax

      DELETE [<scope>] [WHILE <lCondition>]
             [FOR <lCondition>]

Arguments

<scope> is the portion of the current database file to DELETE. If a scope is not specified, DELETE acts only on the current record. If a conditional clause is specified, the default becomes ALL records.

WHILE <lCondition> specifies the set of records meeting the condition from the current record until the condition fails.

FOR <lCondition> specifies the conditional set of records to DELETE within the given scope.

Description

DELETE is a database command that tags records so they can be filtered with SET DELETED ON, queried with DELETED(), or physically removed from the database file with PACK. In addition, display commands such as LIST and DISPLAY identify deleted records with an asterisk (*) character. Once records are deleted, you can reinstate them by using RECALL. If you want to remove all records from a database file, use ZAP instead of DELETE ALL and PACK.

Any deleted record can be recalled as long as the PACK or ZAP command has not been issued. Once the PACK or ZAP command has been issued, the deleted data cannot be retrieved.

In a network environment, DELETE requires the current record be locked with RLOCK() if you are deleting a single record. If you are deleting several records, the current database file must be locked with FLOCK() or USEed EXCLUSIVEly. Refer to the “Network Programming” chapter in the Programming and Utilities Guide for more information.

Notes

. DELETE with SET DELETED ON: If the current record is deleted with SET DELETED ON, it will be visible until the record pointer is moved.

Examples

      .  This example demonstrates use of the FOR clause to mark a set
         of records for deletion:
      USE Sales INDEX Salesman NEW
      DELETE ALL FOR Inactive

Seealso

DBEVAL(), DELETED(), FLOCK(), PACK, RECALL, RLOCK()

COUNT

COUNT

Tally records to a variable

Syntax

      COUNT TO <idVar>
             [<scope>] [WHILE <lCondition>] [FOR <lCondition>]

Arguments

TO <idVar> identifies the variable that holds the COUNT result. A variable that either does not exist or is invisible is created as a private variable whose scope is the current procedure.

<scope> is the portion of the current database file to COUNT. The default is ALL records.

WHILE <lCondition> specifies the set of records meeting the condition from the current record until the condition fails.

FOR <lCondition> specifies the conditional set of records to COUNT within the given scope.

Description

COUNT tallies the number of records from the current work area that match the specified record scope and conditions. The result is then placed in the specified variable. <idVar> can be a variable of any storage class including a field.

Examples

      .  This example demonstrates a COUNT of Branches in Sales.dbf:
      USE Sales NEW
      COUNT TO nBranchCnt FOR Branch = 100
      ? nBranchCnt                           // Result: 4
      .  This example tallies the number of records in Sales.dbf whose
      Branch has the value of 100 and assigns the result to the Count field
      in Branch.dbf for branch 100:
      USE Branch INDEX Branch NEW
      SEEK 100
      USE Sales INDEX SalesBranch NEW
      SEEK 100
      COUNT TO Branch->Count WHILE Branch = 100

Seealso

AVERAGE, DBEVAL(), SUM, TOTAL

AVERAGE

AVERAGE

Average numeric expressions in the current work area

Syntax

      AVERAGE <nExp list> TO <idVar list>
             [<scope>] [WHILE <lCondition>] [FOR <lCondition>]

Arguments

<nExp list> is a list of the numeric values to AVERAGE for each record processed.

TO <idVar list> identifies a list of receiving variables which will contain the average results. Variables that either do not exist or are not visible are created as private variables. <idVar list> must contain the same number of elements as <nExp list>.

<scope> defines the portion of the current database file to AVERAGE. The default scope is ALL.

WHILE <lCondition> specifies the set of records meeting the condition from the current record until the condition fails.

FOR <lCondition> specifies the conditional set of records to AVERAGE within the given scope.

Description

AVERAGE calculates the average of one or more numeric expressions to variables for a range of records in the current database file. Zero values are counted in the AVERAGE unless explicitly ruled out with a FOR condition.

Examples

      .  This example averages a single numeric field using a condition
         to select a subset of records from the database file:
      USE Sales NEW
      AVERAGE Amount TO nAvgAmount FOR Branch = "100"
      .  This example finds the average date for a range of dates:
      AVERAGE (SaleDate - CTOD("00/00/00")) ;
         TO nAvgDays FOR !EMPTY(SaleDate)
      dAvgDate := CTOD("00/00/00") + nAvgDays

Seealso

DBEVAL(), SUM, TOTAL

Harbour All Functions – D

Date()
Day()
Days()

DaysInMonth()
DaysToMonth()

dbAppend()
dbClearFilter()
dbCloseAll()
dbCloseArea()
dbCommit()
dbCommitAll()
dbCreate()
dbDelete()
dbEval()
dbF()
dbFilter()
dbGoBottom()
dbGoTo()
dbGoTop()
dbReCall()
dbRLock()
dbRLockList()
dbRUnlock()
dbSeek()
dbSelectArea()
dbSetDriver()
dbSetFilter()
dbSkip()
dbSkipper()
dbStruct()
dbUnlock()
dbUnlockAll()
dbUseArea()

DecToBin()
DecToHexa()
DecToOctal()

Deleted()
Descend()
DevOutPict()
DirChange()
DirRemove()
DiskSpace()

DMY()
Do()
DoW()

DOY
DToC()

DToR
DToS()

Harbour Database Functions

Database Functions

AFields Fills referenced arrays with database field information
Alias Returns the alias name of a work area
BOF Test for the beggining-of-file condition
dbAppend Appends a new record to a database file
dbClearFilter Clears the current filter condiction in a work area
dbCloseAll Close all open files in all work areas.
dbCloseArea Close a database file in a work area
dbCommit Updates all index and database buffers for a given workarea
dbCommitAll Flushes the memory buffer and performs a hard-disk write
dbCreate Creates an empty database from a array
dbDelete Mark a record for deletion in a database
dbEval Performs a code block operation on the current Database
DBF Alias name of a work area
dbFilter Return the filter expression in a work area
dbGoBottom Moves the record pointer to the bottom of the database
dbGoto Position the record pointer to a specific location
dbGoTop Moves the record pointer to the top of the database
dbRecall Recalls a record previousy marked for deletion
dbSeek Searches for a value based on an active index
dbSelectArea Change to another work area
dbSetDriver Establishes the RDD name for the selected work area
dbSetFilter Establishes a filter condition for a work area
dbSkip Moves the record pointer in the selected work area
dbSkipper Helper function to skip a database
dbStruct Builds a multidimensional array of a database structure
dbUseArea Opens a work area and uses a database file
Deleted Tests the record’s deletion flag
EOF Test for end-of-file condition
FCount Counts the number of fields in an active database
FieldDeci Determines the number of decimal places of a given numeric field
FieldGet Obtains the value of a specified field
FieldName Return the name of a field at a numeric field location
FieldPos Return the ordinal position of a field
FieldPut Set the value of a field variable
FieldSize Determines the size of a given field
FieldType Determines the type of a given field
Found Determine the success of a previous search operation
Header Return the length of a database file header
LastRec Returns the number of records in an active work area or database
LUpdate Yields the date the database was last updated
RecCount Counts the number of records in a database
RecNo Returns the current record number or identity
RecSize Returns the size of a single record in an active database
Select Returns the work area number for a specified alias
Used Checks whether a database is in use in a work area

PACK

PACK

Remove records marked for deletion from a database

Syntax

      PACK

Arguments

(This command has no arguments)

Description

This command removes records that were marked for deletion from the currently selected database. This command does not pack the contents of a memo field; those files must be packed via low-level fuctions.

All open index files will be automatically reindexed once PACK command has completed its operation. On completion, the record pointer is placed on the first record in the database.

Examples

      USE tests NEW INDEX tests
      DBGOTO( 10 )
      DELETE NEXT 10
      PACK
      USE

Compliance

Clipper

Seealso

DBEVAL(), DELETE, DELETED(), ZAP, RECALL

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()

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()