Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
RECNO() returns 1 for no records
Message
From
03/05/2004 10:08:56
 
 
To
03/05/2004 09:59:32
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivia
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00900340
Message ID:
00900367
Views:
15
Hiya Hilmar. Yeah I got all that. I was expressing rather the weirdness of have a recno() value greater than zero if there are no records at all! Logically this is clearly not right. I appreciate this has been around for a while but that does'nt make it correct :) But hey, it's all part of the beauty of VFP!

Later!



>>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.
In the End, we will remember not the words of our enemies, but the silence of our friends - Martin Luther King, Jr.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform