How to Save & Restore Record Pointer Without Negative EOF MarkID: Q147169 3.00 3.00b WINDOWS
The information in this article applies to:
SUMMARYProgrammers frequently store record pointer information to a memory variable before a program accesses a table, so that they can restore the record number once the processing is finished. This article provides an alternative to using negative numbers to indicate the end of a file.
MORE INFORMATIONA typical example to save and restore record pointer information is as follows: LOCAL lnRecNumber SELECT Labels ********************** * Save record Number * ********************** lnRecNumber= IIF(EOF('Labels', -1, RECNO('Labels')) ************************
* Restore record Number*
************************
IF lnRecNumber > 0
ENDIF
In this example, the negative number -1 is used to flag the end of the file (EOF). However, using this approach might not yield the expected results when you work with local views or when buffering is enabled. When you enable buffering on a table, Visual FoxPro writes the records to a buffer and permits edits until you issue a TABLEUPDATE() command. Every new record is assigned a negative number while the data is buffered. The record number is decremented as you add records. For example, the first record you add has a value of -1, the second is -2, and so on. The following code sample illustrates how Visual FoxPro assigns record numbers when table buffering is enabled.
Sample CodeSET EXCLUSIVE OFF CREATE TABLE TEST (cName C(10)) SET MULTI ON =CURSORSETPROP("Buffering",5) WAIT WINDOW "Appending Data" NOWAIT ? "Record number before the data is committed" =AddRec("Name 1") =AddRec("Name 2") =AddRec("Name 3") WAIT WINDOW "Commiting the Changes" NOWAIT =TABLEUPDATE(.T.) WAIT CLEAR ? ? "Record number after the data is committed" SCAN ENDSCAN
FUNCTION AddRec LPARAMETER cName INSERT INTO test VALUES (cName) ? "Record Number: " ?? RECNO()
Alternative to Using a Negative NumberThe alternative to using a negative number to store the end of the file is to use the .NULL. value. In the first code sample, the line that read:
can be changed to:
You can use the ISNULL() function to verify whether the record pointer is
at the end of the file. For more information about ISNULL(), search for
ISNULL() in the Help file.
Additional reference words: 3.00 3.00b VFoxWin KBCategory: kbhowto KBSubcategory: FxprgGeneral
|
Last Reviewed: May 22, 1998 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |