Subject Re: Repair a corrupted DBT file
From Mervyn Bick <invalid@invalid.invalid>
Date Sat, 27 Mar 2021 14:14:48 +0200
Newsgroups dbase.getting-started

On 2021/03/27 11:56, Tim Ward wrote:

> 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?

Before we go any further, make sure you are working on copies of the
.dbf and .dbt file.  Use Windows or DOS, not dBASE, to copy the two files.

As dBASE is a 32-bit program it can only use 6GB no matter how much
memory is in the computer.  But even with the minimum 4GB that dBASE
recommends one should seldom run out of memory.

The probable cause is that the bocksize in the .dbt file is not 1024.
The memo is held in 4 bytes.  In the normal course of events bytes 3 and
4 (and most likely byte 2 as well) will be zero.  If the blocksize is
actually, say, 512 then the program is most likely finding values ins
bytes 2, 3 and 4 which result in massive calculated value.

In hindsight (hindsight is 20/20 vision :-) ) I should have added code
to determine the blocksize in the dbt file instead of simply using 1024.

The blocksize is determined by a setting in BDEAdministrator.exe and
I've noticed recently that this seems to default to 512 rather than 1024
which seemed to be the norm in the past but it can actually be any
multiple of 128.  The value used for a specific .dbt file is stored in
bit 21 i.e 0x15 (counting from 0 for the first bit) of the header.
Multiply this value by 128 to get the blocksize.

I assume you have a hex editor (I use XVI32) which you used to change
the 4D0A in the .dbf file header to 430A.  This changes the field type
from M (memo) to C (character).

If you browse the .dbf file you should see a numeric value in the field.
  Depending on how long your individual memos are they should vary
between 1 and perhaps twice the number of records in your .dbf file.
They need not necessarily be in order.

Open the .dbt file in the hex editor and check the value in byte 0x15.
If it is not 04 change the value of the blocksize in the program
appropriately.  You will, of course, also need to edit in the correct
name of the memo field.

Mervyn.