Get# for DBF format
I am using GET# to read a DBF header.
Here are the declarations
And here is how I read them in:
Private Type HeaderInfo
bytVersion As Byte
bytYear As Byte
bytMonth As Byte
bytDay As Byte
lngNumberRecords As Long
intHeaderLength As Integer
intLengthRecords As Integer
strPadding As String * 20
Dim Header As HeaderInfo
Open "e:\research\reefs\Lord howe data (orig)\bathy_gis\lads_data\lads.dbf" _ For Binary As #1 Len = 32
Get #1, 1, Header.bytVersion
Get #1, 2, Header.bytYear
Get #1, 3, Header.bytMonth
Get #1, 4, Header.bytDay
Get #1, 5, Header.lngNumberRecords
Get #1, 9, Header.intHeaderLength
Get #1, 11, Header.intLengthRecords
Get #1, 13, Header.strPadding
Even though the numbers that I get in seem correct, if I add them to a text box each variable is preceeded and followed by unprintable characters - newlines/carriage returns I think. How do I get rid of these as I input the data??
Try to read the header in one shot (this is what I do for bmp files)
Dim hdr As BITMAPFILEHEADER
fileno = FreeFile
Open file For Binary Access Read As fileno
Get fileno, , hdr
Yeah, that's how I was reading it in originally, same problem.
I dont understand how I can read in a long, for example and it returns the correct number but it is preceeded by a carriage return and linefeed. How do I strip the first two character off a long integer?
Now I saw that in the original structure declaration some parameter is defined as Byte. That is quite unusual, because can cause 'padding' problems (that is, some languages automatically expand any paramater to be a multiple of a word)
Are all parameters wrong or only some of them?
Can you post the dbf file you are trying to read?
Thanks for your help.
I also tried declaring those parameters as String *1, but same problem
I've attached a similar DBF top the one in question... the one I am using zipped to 100.5 kb, and the limit on the forum is 100 kb!
Ok, the carriage return and line feeds are actually my textboox playing up...I dont know why it isnt putting in new lines.
If leaving it as bytes is working should I change it to something else? Also, I am reading in the field names as strings * 10 - which includes all the null bytes - is there a better way to do this?
if the string written in the file are 10 characters long then you have to read them that way.
To strip the trailing blanks:
dim newString as String
dim k as long
k= instr(oldString, chr(0))
if k > 0 then
newstring = oldstring
Ok, thanks for that Marco.
-- Android Development Center
-- Cloud Development Project Center
-- HTML5 Development Center
-- Windows Mobile Development Center