Microsoft KB Archive/135616

= How to Remove Records from a Table Without Using Delete/Pack =

Article ID: 135616

Article Last Modified on 12/3/2003

-

APPLIES TO


 * Microsoft Visual FoxPro 3.0 Standard Edition
 * Microsoft FoxPro 2.0
 * Microsoft FoxPro 2.5b for MS-DOS
 * Microsoft FoxPro 2.5a
 * Microsoft FoxPro 2.6 for MS-DOS
 * Microsoft FoxPro 2.6a Standard Edition
 * Microsoft FoxPro 2.5b
 * Microsoft FoxPro 2.5a
 * Microsoft FoxPro 2.5b
 * Microsoft FoxPro 2.6 Standard Edition
 * Microsoft FoxPro 2.6a Standard Edition

-



This article was previously published under Q135616



SUMMARY
Using the DELETE or PACK commands to remove records can be very time consuming. ZAP is very fast, but removes all the records. With FoxPro's low-level file I/O, you can quickly remove a select number of unwanted records from the end of a table.



Step-by-Step Procedure
  Open a program file, name it Lowlevel.prg, and type the following function code: FUNCTION ZAPLAST PARAMETER lnY IF USED lnZ=RECCOUNT IF lnY<=lnZ lcFILENAME=DBF USE lnHANDLE=FOPEN(lcFILENAME,2) IF lnHANDLE>0 lcBYTE=FREAD(lnHANDLE,32) lnFLD_SIZE=ASC(SUBSTR(lcBYTE,11,1))+; (ASC(SUBSTR(lcBYTE,12,1))*256) lnFILESIZE=FSEEK(lnHANDLE,0,2) lnX=lnZ-lnY lcBYTE8=CHR(INT(lnX/(256*256*256))) lcBYTE7=CHR(INT(lnX/(256*256))) lcBYTE6=CHR(INT(lnX/256)) lcBYTE5=CHR(MOD(lnX,256)) lcBYTE=SUBSTR(lcBYTE,1,4)+lcBYTE5+; lcBYTE6+lcBYTE7+lcBYTE8+SUBSTR(lcBYTE,9) =FSEEK(lnHANDLE,0) =FWRITE(lnHANDLE,lcBYTE) =FCHSIZE(lnHANDLE,lnFILESIZE+(lnFLD_SIZE*lnX)) =FCLOSE(lnHANDLE) ENDIF USE &lcFILENAME ENDIF ENDIF  Save and close Lowlevel.prg Test the function by removing a single record from a table. For this example, use the Customer.dbf table - but back up the table first. Records that are deleted with ZAPLAST cannot be recovered.   In the Command window, type: SET PROCEDURE TO LOWLEVEL.PRG USE C:\FPW26\TUTORIAL\CUSTOMER EXCLUSIVE  Take note of how many records are in the table. For this example, there are 500 records.  In the Command window, type: =ZAPLAST(1)  Note that there is one less record in the database. Originally there were 500 records; now there are only 499.</li></ol> </li> Any number of records can be deleted. For example, to delete 27 records, change step 3.c. to =ZAPLAST(27)</li></ol>

NOTE: Only records at then end of the table can be deleted with ZAPLAST. ZAPLAST will not recognize index orders or Visual FoxPro triggers.

Additional query words: VFoxWin FoxWin FoxDos

Keywords: KB135616

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.