Reading binary file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ziopulcher
    New Member
    • Apr 2009
    • 1

    Reading binary file

    Good morning.
    I need some help in order to load a binary file.
    I know that the first 3200 bytes of this file are a "text" header (40 rows x 80 columns). I tried to read them by using the "get" instruction, but I don't know how to convert in the ascii text i have just numbers.
    May somebody help me? Thank you very much
  • ems9tech
    New Member
    • Apr 2009
    • 12

    #2
    The key is to initialize the string to something with its exact length
    strWork = String(lByteLen , " ")

    Here's a sample from what I've done:
    Code:
        If fs.FileExists(sfile) Then
    
            'get an available file handle
            iFile = FreeFile
    
            'open the file for access
            Open sfile For Binary As iFile
    
            'get current len of file
            lByteLen = LOF(iFile)
    
            'grab file contents
            If lByteLen <= 500000 Then 'Read Entire file
                'initialize the string to something with its length
                strWork = String(lByteLen, " ")
                Get iFile, 1, strWork
            Else                      'Read End only in case it's REALLY B I G
                strWork = String(250, " ")
                Get iFile, (lByteLen - 249), strWork
            End If
    
            If lByteLen > 2000000 Then  'If Bigger than 2 MB, won't send via Email
                fETraceTooBigForEmail = True
            End If
    
            'must close file when done
            Close iFile
    
            If InStr(1, strWork, "No Errors Encountered") = 0 Then
                'String not found
            End If
            'Delete original Trace file - if an error, we made a copy - ETrace
            If fs.FileExists(sfile) Then fs.DeleteFile sfile, True
        End If
    Last edited by debasisdas; Apr 21 '09, 06:25 AM. Reason: added code tags

    Comment

    Working...