Click or drag to resize

OrdKeyCount Function

X#
Return the number of keys in an order.

Namespace:  XSharp.RT
Assembly:  XSharp.RT (in XSharp.RT.dll) Version: 2.19
Syntax
 FUNCTION OrdKeyCount(
	uOrder,
	cIndexFile
) AS USUAL CLIPPER
Request Example View Source

Parameters

uOrder (Optional)
Type: Usual
The name of the order or a number representing its position in the order list.
Using the order name is the preferred method since the position may be difficult to determine using multiple-order index files.
If omitted or NIL, the controlling order is assumed.
Specifying an invalid order will raise a runtime error.
cIndexFile (Optional)
Type: Usual
The name of an index file, including an optional drive and directory (no extension should be specified).
Use this argument with cOrder to remove ambiguity when there are two or more orders with the same name in different index files.
If cIndexFile is not open by the current process, a runtime error is raised.

Return Value

Type: Usual
Remarks
OrdKeyCount() counts the keys in the specified order and returns the result as a numeric value.
If the order is not conditional and no scope has been set for it, OrdKeyCount() is identical to RecCount(), returning the number of records in the database file. However, for a conditional order, there may be fewer keys than there are records, since some records may not meet the order's for condition or may not fall inside the scope specified by OrdScope() — in counting the keys, OrdKeyCount() respects the currently defined scope and for condition. By default, this function operates on the currently selected work area.
It can be made to operate on an unselected work area by specifying it within an aliased expression

If there is no order in operation, the return value will be 0 and not the value of RecCount().
Examples
This example demonstrates using OrdKeyCount() with various orders.
X#
 1USE customer
 2// Assume 1000 total records,
 3// 500 less than thirty years old, and
 4// 895 making less than 50,000
 5? RecCount()                    // Result: 1000
 6? OrdKeyCount()            // Result: 0
 7INDEX ON Age TO Age
 8INDEX ON First TO First FOR Age < 30
 9INDEX ON Last TO Last FOR Salary < 50000
10// Age is the controlling order
11SET INDEX TO Age, First, Last
12? RecCount()                    // Result: 1000
13? OrdKeyCount()            // Result: 1000
14? OrdKeyCount("First")        // Result: 500
15? OrdKeyCount(3)            // Result: 895
See Also