Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
RECNO() returns 1 for no records
Message
From
03/05/2004 09:59:32
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivia
 
 
To
03/05/2004 08:50:36
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00900340
Message ID:
00900361
Views:
18
>Hi All. Can anyone explain the logic that RECNO() should return a value of 1 when a file has no records? VFP8/SP1. Its in the docs but why? Surely RECNO() should return 0 if there are no records?

It is weird, but it's not a bug; it is intentional.

Think of it as follows: If you go to the last record (if there is one) and then do a SKIP, you are AFTER the last record. (In this case, recno() = reccount() + 1, and eof() = .T. If you issue SKIP again, you get an error message.)

If you don't have any records, OR if you have a filter that excludes all records, you will be after the last record.

You can test whether you are on a valid record, either by checking not eof(), or recno() < = reccount(). (Note that new, unsaved records will have negative record numbers.)

A more serious issue, IMO, is the inconsistency in the use, between eof() and bof().

With GO BOTTOM and SKIP, you are after the last record, recno() = reccount() + 1, eof() = .T., and ? SomeField will show you empty data.

With GO TOP and SKIP -1, you are still on the first record, recno() = 1, bof() = .T., and ? SomeField will show you the data from the first record. (Inconsistencies in bold.) IOW, you can use bof() for testing, whether you go back beyond the first record, but you should not try to do anything with the records, that would depend on you being positioned on a valid record.

Greetings,

Hilmar.
Difference in opinions hath cost many millions of lives: for instance, whether flesh be bread, or bread be flesh; whether whistling be a vice or a virtue; whether it be better to kiss a post, or throw it into the fire... (from Gulliver's Travels)
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform