Click or drag to resize

RecNo Function

X#
Return the current record number.

Namespace:  XSharp.RT
Assembly:  XSharp.RT (in XSharp.RT.dll) Version: 2.19
Syntax
 FUNCTION RecNo() AS DWORD
Request Example View Source

Return Value

Type: DWord
The current record number.
If the work area contains a database file with 0 records, RecNo() returns 1, BOF() and EOF() both return TRUE, and LastRec() returns 0. If the record pointer is moved past the last record, RecNo() returns LastRec() + 1 and EOF() returns TRUE.
If an attempt is made to move before the first record, RecNo() returns the record number of the first logical record in the database file and BOF() returns TRUE.
If no database file is open, RecNo() will return a 0.
Remarks
X# database files are physically ordered by record number.
Each work area in turn maintains a pointer to the current record in its open database file. That record number is reported by RecNo().
This allows direct access to a record without sequentially scanning the database file to reach the specified record position. Typically, RecNo() generalizes routines that process records by record number.
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 or by calling the overload that accepts a workarea parameter (a workarea number or alias ).
Examples
This example queries RecNo() after deliberately moving the record pointer:
X#
 1USE customer NEW
 2GO 3
 3QOut(RECNO())                // Result: 3
 4GO TOP
 5QOut(RECNO())                // Result: 1
 6nRecord := 3
 7GO nRecord
 8QOut(RECNO())                // Result: 3
 9DBGoBottom()
10SKIP
11QOut(RECNO(), LastRec())        // Result: 11 10
This example uses aliased expressions to query the value of RecNo() in unselected work areas:
X#
1USE sales NEW
2USE customer NEW
3QOut(Sales->RECNO())
4QOut(Customer->RECNO())
See Also