xHarbour Reference Documentation > Command Reference xHarbour Developers Network  

COUNT

Counts records in the current work area.

Syntax

COUNT TO <varName> ;
        [<Scope>] ;
  [WHILE <lWhileCondition>] ;
    [FOR <lForCondition>]

Arguments

TO <varName>
The name of the variable that is assigned the result of the COUNT operation. When <varName> does not exist, it is created as a PRIVATE variable.
<Scope>
This option defines the number of records to process. It defaults to ALL. The NEXT <nCount> scope processes the next <nCount> records.
WHILE <lWhileCondition>
This is a logical expression indicating to continue counting while the condition is true. The COUNT operation stops as soon as <lWhileCondition> yields .F. (false).
FOR <lForCondition>
This is a logical expression which is evaluated for all records in the current work area. Those records where <lForCondition> yields .T. (true) are included in the count.

Description

The COUNT command is used to count the number of records in the current work area based on the result of one or more logical expressions. The expressions are evaluated in the current work area. The number of records to include in the count can be restricted using a FOR and/or WHILE condition or by explicitely defining a scope.

Info

See also:AVERAGE, DbEval(), SUM, TOTAL, UPDATE
Category: Database commands
Source:rdd\dbcmd.c
LIB:xhb.lib
DLL:xhbdll.dll

Example

// The example counts the number of sales that exceed a limit

   PROCEDURE Main
      LOCAL nSales := 0

      USE Sales NEW
      COUNT TO nSales FOR FIELD->Amount * FIELD->Price > 500
      USE

      ? "Sales of more than 500:", nSales
   RETURN

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe