ADBOBJECTS()

BOF(), EOF()

She was a phantom of delight
When first she gleamed upon my sight;

William Wordsworth, She Was a Phantom of Delight, 1807

These functions stand for Beginning Of File and End Of File, respectively. They tell you whether the record pointer is at the start or end of a table or cursor.

Usage

lReturnValue = BOF( [cAlias | nWorkArea] ) lReturnValue = EOF( [cAlias | nWorkArea] )

Parameter

Value

Meaning

cAlias

Character

Check the table whose alias is cAlias.

Omitted

If nWorkArea is also omitted, check the table in the current work area.

nWorkArea

Numeric

Check the table currently open in nWorkArea.

Omitted

If cAlias is also omitted, check the table in the current work area.

lReturnValue

.T.

The specified table is at the beginning or end of file, based on the current order.

.F.

The specified table is not at the beginning or end of file.


BOF() and EOF() are not complementary as their names imply. Instead, we have one of those little inconsistencies that drive us all nuts. BOF() means at the beginning of the file; EOF() means beyond the end of the file. BOF() becomes true when you skip backward from the first record (in the current order), but the record pointer remains on the first record. However, every Xbase table has a "phantom" record at the end. EOF() is true when the record pointer is pointing to the phantom record, not to the last real record in the table. So the mechanism for getting to BOF() and EOF() is the same—skip backward or forward from the first or last record—but the results are not.

EOF() is useful when a relation has been set between two tables. If you move the record pointer in the parent table, and there are no matching records in the child table, EOF() becomes true for the child table. This is an easy way to check for matching records. Incidentally, you can do the same thing by checking FOUND() in the child area.

Besides a lack of relatives, various things can set the record pointer to EOF(). The simplest is to issue SKIP when you're already on the last record. Other things that leave the pointer on EOF() are a SEEK or SEEK() (with SET NEAR OFF) that doesn't find a match, a LOCATE that doesn't locate any matching records, and any of the scoped commands (like REPLACE or COUNT) issued with ALL or REST, and no WHILE clause to stop them sooner.

We recommend strongly that you never use work area numbers as parameters to BOF() and EOF() (or just about any other time, actually). While it's always been better to avoid them, this is even more true in Visual FoxPro, since the visual interface no longer provides a way to choose work areas by number.

Example

USE Customer ? RECNO()   && 1 ? BOF()     && .F. * make BOF() true SKIP –1 ? BOF()     && .T. ? RECNO()   && Still 1   * now go to the bottom GO BOTTOM ? EOF()      && .F. ? RECNO()   * go to phantom record SKIP ? EOF()     && .T. ? RECNO()   && Not the same as above;             && one more than RECCOUNT()   * check for related records USE Parent IN 0 USE Child IN 0 ORDER ParentId   SELECT Parent SET RELATION TO ParentId INTO Child   * Browse child-less parents BROWSE FOR EOF("Child") * Another way to do this is: BROWSE FOR NOT FOUND("Child")

See Also

Go, Locate, Seek, Seek(), Set Near, Set Relation, Skip


View Updates

Copyright © 2002 by Tamar E. Granor, Ted Roche, Doug Hennig, and Della Martin. All Rights Reserved.



Hacker's Guide to Visual FoxPro 7. 0
Hackers Guide to Visual FoxPro 7.0
ISBN: 1930919220
EAN: 2147483647
Year: 2001
Pages: 899

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net