Condividi tramite


RECNO( ) Function

Returns the current record number in the current or specified table.

RECNO([nWorkArea | cTableAlias])

Return Values

Numeric

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.

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.

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.

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

See Also

GO|GOTO | RECCOUNT( ) | RECSIZE( ) | SEEK | SKIP