Results 1 to 4 of 4

Thread: reading from binary files

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2003
    Posts
    6

    reading from binary files

    I am trying to read from a binary file. I am getting some weird input however.
    The binary file is called "my file.bin" and contains these simple hex
    characters:

    F7 00 00 08 F0

    I want to be able to insert every pair of hex data into a simple array. Here's
    the code I've produced...

    Private Sub button_Click()
    Dim data As Integer
    Dim small_array(1 to 5) as Integer
    nFileNum = FreeFile
    picBox.Cls

    Open App.Path & "\" & "my file.bin" For Binary As #nFileNum

    for i = 1 to 5
    Get #nFileNum, i, data
    small_array(i) = data
    Next

    for i = 1 to 5
    picBox.print Hex(small_array(i))
    Next

    Close #nFileNum
    End Sub


    When the code is executed, I get this result:

    F7 0 800 F008 F0

    Can someone tell me what is happening, why Visual Basic is producing these
    results, and how I can fix this? Thank you!

  2. #2
    Fanatic Member
    Join Date
    Feb 2003
    Location
    Los Angeles, CA
    Posts
    681
    does your file contain 5 bytes? or does it contain the string "F7 00 00 08 F0"?
    there are 2 reasons why i leave my work unfinished:
    (1) i'm getting old.

  3. #3
    Frenzied Member
    Join Date
    Aug 2000
    Location
    O!
    Posts
    1,177
    For starters, you are reading 2 of the 5 bytes with every Get because the variable data is an Integer. Try changing data to Byte and see if it doesn't work.

    I got basically the same results when reading the file as though it contains Integers. I should think that VB would raise a read past EOF type error.

  4. #4

    Thread Starter
    New Member
    Join Date
    May 2003
    Posts
    6

    issue resolved

    Changing the variable data into a type byte fixed the problem! Thank you very much!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width