Article ID: 135040
Article Last Modified on 9/30/2003
*** Program to demonstrate the effect of PACK
*** on open index files in Visual FoxPro
*** Test program named Testpack.prg
CLEAR
SET SAFETY OFF
CLEAR ALL
CLOSE ALL
********Creation of testfile
DECLARE new_dbf[1,4]
new_dbf[1,1] = "Pagenum"
new_dbf[1,2] = "N"
new_dbf[1,3] = 4
new_dbf[1,4] = 0
SELECT 0
CREATE TABLE temptabl FROM ARRAY new_dbf && It's in USE
INDEX ON Deleted() TAG Deleted && .CDX is also in USE
INDEX ON Pagenum TAG Pagenum
SET ORDER TO
COPY TO Temptbl2 WITH PRODUCTION && On the disk so
RENAME Temptbl2.dbf TO testfile.dbf && Can rename.
RENAME Temptbl2.cdx TO testfile.pax && Now not structural.
* Index file has multiple tags. It is a non-structural compound
* index file. A single index file with the extension of .idx
* will also demonstrate the issue.
USE testfile INDEX testfile.pax ALIAS testfile EXCLUSIVE
SET ORDER TO
**** Add some records then delete some
SELECT testfile
FOR q = -10 to 50 && 60 records
APPEND BLANK
REPLACE Pagenum WITH q
IF q/3 == INT(q/3) && Every third record
DELETE
ENDIF
ENDFOR
CLEAR
WAIT WINDOW "About to display status." ;
+ chr(13) + ;
"Please notice that the table has its index file open."
DISPLAY STATUS
WAIT
CLEAR
WAIT WINDOW "About to pack."
PACK
WAIT WINDOW "About to display status again." ;
+ chr(13) + ;
"Please notice that the index file has been closed."
DISPLAY STATUS
WAIT
WAIT WINDOW "Use Alt+I to bypass the next message, but" ;
+ chr(13) + ;
"read it first - you're trying to use a closed index."
SET ORDER TO 1
BROWSE NOWAIT
WAIT WINDOW "Every 3rd record was deleted. Packing removed them." ;
+ chr(13) + ;
"But, as you have seen, the index file was closed." ;
+ chr(13) + ;
"See if the index still exists. Watch the status bar."
ERASE testfile.pax
WAIT WINDOW "The message - File has been deleted - says" ;
+ chr(13) + ;
"The index file was closed and could be deleted."
CLOSE ALL
ERASE temptabl.dbf && Clean up afterwards.
ERASE temptabl.cdx
ERASE temptbl2.dbf
ERASE temptbl2.cdx
ERASE testfile.dbf
ERASE testfile.pax
CLEAR
RETURN
***** End of test program.
Keywords: kbbug kbfix kbvfp500fix KB135040