1

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.

1 Answer 1

4

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
Sign up to request clarification or add additional context in comments.

2 Comments

That did it! Why is this not necessary on the other values?
@Richard, Probably because the offset of the max number of fields would exceed 255 bytes, but with 2 bytes with low/hi order will allow up to a header of 65535 bytes (would never happen), so they only needed two bytes worth.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.