Reading binary files

Discussion in 'Questions (Windows Mobile)' started by jgm, May 25, 2008.

  1. jgm

    jgm Member Licensed User

    I need to read a dbase III file (*.dbf), change a few records and write it back.
    As I do not know a better way to do it, I'm trying to open it as a binary file,
    I tried reading help on binary files but couldn't get what I need to know.
    I managed to read one file, in binary mode, using ReadBytes, but got an error message when trying to assign what I read to a string using BytesToString (help file says BytesToString returns a string):
    length = bin.ReadBytes(buffer(),5)
    Version = bin.BytesToString(buffer(),1,3)
    What am I missing?

    I have a text file that has just two chars "AB".
    A is ASCII 65 (41HEX) and B is ASCII 66 (42HEX).
    I read the file in binary mode using
    in_data = bin.ReadInt16
    and printed in_data in a MsgBox; got the decimal value 16961, which means (I think) that those bytes are dealt in reverse order "BA", otherwise I would get for "AB" = 41HEX 42HEX = 16706 decimal.
    Is that so, I mean, are bytes in binary numbers written in reverse order?
  2. agraham

    agraham Expert Licensed User

    Might be useful to know what the error message and byte data was?
    Yes, numerics are usually written least significant byte first (on Wintel systems at least).
    EDIT : That is true of binary numerics. I seem to remember (dredges deeply!) that in dBase files numerics are actually stored as strings.
    Last edited: May 25, 2008
  3. jgm

    jgm Member Licensed User

    The file I'm reading is a text file with five chars "ABCDEF".

    I believe I found what was happening.
    I assigned what I read to a variable named Version and I got the message:
    "Error compiling program.
    Error description: Illegal first word in line.
    Occured on line: 37
    Version= bin.BytesToString(buffer(),1,3)"

    Version must be a reserved word because after changing variable's name to VVersion I got no more error messages.

    Thank you for your help.
  4. jgm

    jgm Member Licensed User

    More than one Binary File open at the same time?

    Is it possible to have more than one Binary File open at the same time, for example, one for reading and the other for writing?

    If so, how can you tell which file you are referring to when using instructions like:
  5. klaus

    klaus Expert Licensed User

    You must define 2 binary file objects like and open the 2 files.


    This should work.

    Best regards.
  6. jgm

    jgm Member Licensed User

    It worked fine.
    Thank you for your help.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice