Question

I am opening a DBF as a binary file in VB.Net to determine the structure. I have to do it this way since using the Visual Foxpro OLEDB driver does not return the precision and scale of decimal fields. I am succesfully accomplishing my task with no problem. The problem I am having is this:

Byte 0 is the DBF file type.
Bytes 1-3 is the Last Update (yymmdd).
Bytes 4-7 of a DBF file is the Number of records in the file.
Bytes 8-9 is the Position of the first data record.
Bytes 10-11 is the Length of one data record, including the delete flag.
(This information comes from http://www.dbf2002.com/dbf-file-format.html)

The following is the first 32 bytes of my DBF file, separated by hyphens:

48-13-2-6-158-0-0-0-168-9-18-3-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-0-1-3-0-0

The "48" (Hex 30) means Visual Foxpro
Bytes 1-3 say that the file was last updated on 2/6/2013.
Bytes 4-7 say that the file has 158 records.
All of these are correct.

Bytes 8-9 are 168 and 9, and Bytes 10-11 are 18 and 3.

The actual record size is 786 bytes. Since there is 68 fields, the position of the first data record should be (68x32+31) = 2207.

Is there some conversion I must do to convert 1689 to 2207 and 183 to 786?

I have tried dec to hex and vice versa.

Was it helpful?

Solution

I think your 2207 is incorrect, but the 786 IS Correct.

I BELIEVE the values are based on low/high byte position being represented by power of 256 as it is also handled within memo files, but 4 bytes worth...

18 * 256^0 ( to the power 0 )  = 18 * 1  = 18
 3 * 256^1 ( to the power 1 )  = 3 * 256 = 768

18 + 768 = 786

Now, the same for the other...

168 * 256^0 ( to the power 0 )  = 168 * 1  = 168
  9 * 256^1 ( to the power 1 )  = 9 * 256 = 2304

168 + 2304 = 2472
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top