Get# for DBF format


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 8 of 8

Thread: Get# for DBF format

  1. #1
    Join Date
    Dec 2004
    Posts
    110

    Get# for DBF format

    Hi,
    I am using GET# to read a DBF header.

    Here are the declarations


    HTML Code:
    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
    
    End Type
    And here is how I read them in:

    HTML Code:
    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
    etc...

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

    Cheers,
    Lithic

  2. #2
    Join Date
    Nov 2003
    Location
    Alameda, CA
    Posts
    1,737
    Try to read the header in one shot (this is what I do for bmp files)
    Code:
        Dim hdr As BITMAPFILEHEADER
        fileno = FreeFile
        Open file For Binary Access Read As fileno
        Get fileno, , hdr
    Marco

  3. #3
    Join Date
    Dec 2004
    Posts
    110
    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?

  4. #4
    Join Date
    Nov 2003
    Location
    Alameda, CA
    Posts
    1,737
    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?
    Marco

  5. #5
    Join Date
    Dec 2004
    Posts
    110
    Hey Marco,

    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!

    Cheers,
    Lithic.
    Attached Files Attached Files

  6. #6
    Join Date
    Dec 2004
    Posts
    110
    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?

    Cheers,
    Lithic


  7. #7
    Join Date
    Nov 2003
    Location
    Alameda, CA
    Posts
    1,737
    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=left$(oldtring, k-1)
    else
    newstring = oldstring
    endif

    Marco

  8. #8
    Join Date
    Dec 2004
    Posts
    110
    Ok, thanks for that Marco.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center