Results 1 to 3 of 3

Thread: Trouble reading a binary file

  1. #1

    Thread Starter
    PowerPoster BruceG's Avatar
    Join Date
    May 2000
    Location
    New Jersey (USA)
    Posts
    2,657
    I thought I'd make a quick utility for myself to extract all ASCII "printable" characters from a file, but unfortunately, this code causes my app to hang when I run it. Can you tell me where I went wrong? (BTW, this is just a quickie, don't yell at me for lack of naming conventions and error handling!)
    Code:
        ' in a command button
        Dim lnglen As Long
        Dim strchar As String * 1
        Dim lngX    As Long
        Dim intFF   As Integer
        
        CommonDialog1.ShowOpen
        
        intFF = FreeFile
        Open CommonDialog1.filename For Binary Access Read As #intFF
        lnglen = LOF(intFF)
        For lngX = 1 To lnglen
            Get #intFF, lngX, strchar
            If Asc(strchar) >= 32 And Asc(strchar) <= 127 Then
                Text1.Text = Text1.Text & strchar
            End If
        Next
        Close #intFF
    TIA for your help ...
    "It's cold gin time again ..."

    Check out my website here.

  2. #2
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    'try this
    'looks like you keep reading the full line over and over
    'just a guess..didn't test this

    Dim lnglen As Long
    Dim strchar As String * 1
    Dim lngX As Long
    Dim intFF As Integer

    CommonDialog1.ShowOpen

    intFF = FreeFile
    Open CommonDialog1.FileName For Binary Access Read As #intFF
    lnglen = LOF(intFF)
    For lngX = 1 To lnglen
    Get #intFF, lngX, strchar
    If Asc(strchar) >= 32 And Asc(strchar) <= 127 Then
    Text1.Text = Text1.Text & strchar
    End If
    strchr = Right(strchr, lnglen - 1)
    Next
    Close #intFF
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  3. #3
    Hyperactive Member
    Join Date
    Mar 2000
    Location
    Boulder, Colorado, USA
    Posts
    325
    it would be better to read a chunk of the data into a buffer string and parse in RAM instead of pulling one byte at a time from the file. This way you can read a buffers worth of data, pull out what you need and repeat until you are done with the file.
    -Shickadance

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