Logo

Hacker’s Guide to Visual FoxPro
An irreverent look at how Visual FoxPro really works. Tells you the inside scoop on every command, function, property, event and method of Visual FoxPro.

SET NEAR, Set(“Near”)

Peace to him that is far off, and to him that is near.
The Bible

This command determines what happens when a search fails. With SET NEAR OFF, the record pointer goes to end of file. SET NEAR ON moves the record pointer to the closest matching record.

Usage

SET NEAR ON | OFF
cNear = SET( "NEAR" )

SET NEAR applies only to searches involving SEEK (and its cousins, SEEK() and INDEXSEEK()), plus the antique FIND. Searches with LOCATE and implied searches due to relations between tables ignore SET NEAR.

“Closest matching record” means the first record after the desired value, that is, the next highest value in an ascending index and the next lowest in descending order. With NEAR OFF, you can use RECNO(0) to explicitly move the record pointer to where you’d have been with NEAR ON.

SET(“NEAR”) tells you the current setting, so you can change it, then reset it. SET NEAR is one of the many settings scoped to a data session.

Example

SET NEAR ON
USE Employee ORDER Last_Name
* An honest man would be handy
SEEK "DIOGENES"
BROWSE  && Record pointer is on record for Anne Dodsworth

See Also

Find, RecNo(), Seek, Set, Set Exact, Set Order