Subject Re: Repair a corrupted DBT file
From Tim Ward <tim@goldengrovenurserydotcodotuk>
Date Sat, 27 Mar 2021 09:56:27 +0000
Newsgroups dbase.getting-started

On 17/11/2013 10:49, Mervyn Bick wrote:
> Open the .dbf file of the corrupt .dbt in the HEX editor and search for
> 4D0A.  Change the 4D to 43 and save the file.  What this does is redefine
> the memo field as a Character field of 10 characters.  If you now list the
> .dbf file you will see a number (actually a character string) in each
> record instead of the memo data.  All your other data should be there.  If
> it isn't you really need a backup file!
>
> The following code is only partially tested. Use it at your own risk.  You
> will need to add code to write the non-memofield fields to the new table
> yourself.  If you get stuck post a copy of the table structure.
>
>
> nBlocksize = 1024
> q = new query()
> q.sql = 'select * from oldfile'
> q.active = true
> q1 = new query()
> q1.sql = 'select * from newfilename'
> q1.active = true
>
> f = new file()
> f.open("oldfile.dbt")
> do while not q.rowset.endofset
>      nBlock = val(q.rowset.fields["memofieldname"].value)
>      nLen = 0
>      f.seek(nBlock*nBlocksize)
>      f.seek(4,1)
>      nSeek = asc(f.read(1))
>      nLen += nSeek
>      nSeek = asc(f.read(1))
>      nLen += nSeek * 0x100
>      nSeek = asc(f.read(1))
>      nLen += nSeek * 0x10000
>      nSeek = asc(f.read(1))
>      nLen += nSeek * 0X1000000
** not enough memory at this line        
>      cRead = f.read(nLen-8)
**
>    //  ?cRead
>      q1.rowset.beginappend()
>      //
>      // code to place data from q.rowset fields to q1.rowset fields
>      //
>      q1.rowset.fields["memofieldname"].value = cRead
>      q1.rowset.save()
>      q.rowset.next()
> enddo
> f.close()
> q.active = false
> q1.active = false
>
>
> Mervyn.
Hi Mervyn,

I have recently had a problem with a corrupted dbt file that
unfortunately I haven't got a recent enough backup for.

I found this thread from 2013 and have got this far. When I run the code
I get an error message ' Not enough memory for this operation' at cRead
= f.read(nLen-8).
Any ideas how to get enough memory? It's a core i5 with 8GB memory so
shouldn't be a problem. Are there some settings in dBase or BDE?

thanks Tim