Returns the current record number in the current or specified table.
RECNO([nWorkArea | cTableAlias]) |
Parameters
- nWorkArea
- Specifies the work area number for a table open in another work area. RECNO(В ) returns 0 if a table isn't open in the work area you specify.
- cTableAlias
- Specifies the table alias for a table open in another work area.
Return Value
Numeric
Remarks
The current record is the record on which the record pointer is positioned.
RECNO(В ) returns negative numbers for records appended in a table buffer.
RECNO(В ) returns a value that is one greater than the number of records in the table if the record pointer is positioned beyond the last record in the table. RECNO(В ) returns 1 if the record pointer is positioned before the first record in the table or the table has no records. If a table has no records, EOF(В ) always returns true (.T.).
RECNO(В ) issued without the optional arguments nWorkArea or cTableAlias returns the current record number for the table in the currently selected work area.
If you have issued SEEK unsuccessfully in an indexed table, you can specify 0 for nWorkArea to use "soft seek" logic to return the record number of the closest matching record. RECNO(0) returns 0 if a close match cannot be found. Visual FoxPro generates an error message if you issue GO RECNO(0) when a close match isn't found.
Avoid using RECNO(В ) in the index expression for a table buffered cursor. Because RECNO(В ) changes for new records when they are committed by TABLEUPDATE(В ), index corruption could occur.
Example
The following example searches the customer
table for a company name, and, if the company name isn't found, uses RECNO(0) to return the closest matching company.
В | Copy Code |
---|---|
CLOSE DATABASES OPEN DATABASE (HOME(2) + 'data\testdata') USE customer && Opens Customer table SET ORDER TO company SEEK 'Ernst' IF FOUND( ) DISPLAY company, contact ELSE GOTO RECNO(0) CLEAR ? 'Closest matching company is ' + company ? 'Record number: ' + ALLTRIM(STR(RECNO( ))) ENDIF |