Microsoft KB Archive/135905

= How to Retrieve Records That Were Previously Zapped =

Article ID: 135905

Article Last Modified on 3/14/2005

-

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.5b for MS-DOS
 * 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 Q135905



SUMMARY
Sometimes, Microsoft Visual FoxPro's ZAP command can be reversed and you can retrieve all the records by using a low-level file I/O. This method works only if the data was not overwritten by other files. The approximate number of records to retrieve is also important.



Step-by-Step Example
  Open a program file named Lowlevel.prg and type in the following function: FUNCTION UNZAP PARAMETER Y  IF Y>0 .AND. USED IF RECCOUNT=0 FILENAME=DBF USE HANDLE=FOPEN(FILENAME,2) IF HANDLE>0 BYTE=FREAD(HANDLE,32) BKUP_BYTE=BYTE FIELD_SIZE=ASC(SUBSTR(BYTE,11,1))+(ASC(SUBSTR(BYTE,12,1))*256) FILE_SIZE=FSEEK(HANDLE,0,2) BYTE8=CHR(INT(Y/(256*256*256))) BYTE7=CHR(INT(Y/(256*256)))                       BYTE6=CHR(INT(Y/256)-IIF(Y/256>256,(INT(INT(Y/256)/256)*256),0)) BYTE5=CHR(MOD(Y,256)) BYTE=SUBSTR(BYTE,1,4)+BYTE5+BYTE6+BYTE7+BYTE8+SUBSTR(BYTE,9) =FSEEK(HANDLE,0) =FWRITE(HANDLE,BYTE) =FCHSIZE(HANDLE,FILE_SIZE+(FIELD_SIZE*Y)) =FCLOSE(HANDLE) ENDIF USE &FILENAME ENDIF ENDIF  Save and close the Lowlevel.prg program file. Back up the table that you are going to experiment on to protect against data corruption. Test the function by zapping the back-up of the table and then use the UNZAP function to retrieve the records. The following example uses the Foxuser.dbf table:   In the Command window, type: SET PROCEDURE TO LOWLEVEL.PRG SET RESOURCE OFF USE FOXUSER  Note how many records are in the foxuser file. For this example, assume that there are 50 records.  In the Command window, type: ZAP =UNZAP(50) </li> Note that all of the records are retrieved.</li></ol> </li> It is possible to use UNZAP to retrieve more records than what actually existed, especially if you do not know exactly how many records to retrieve.

After you use UNZAP, you should browse the table to make sure only valid records were retrieved. Invalid records will immediately be apparent by the incomprehensible data in all the fields. Locate the last valid record and repeat step 4(c) and use the correct number of records.</li> If the Foxuser.dbf table is corrupt, delete the file. FoxPro will create a new one.</li></ol>

Additional query words: VFoxWin FoxWin FoxDos

Keywords: KB135905

-

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

© Microsoft Corporation. All rights reserved.