Searching ASCII in a binary file ? 
Author Message
 Searching ASCII in a binary file ?

I would like help with a small problem with Visual Basic 4.0 32bit:

I need to get some information in a binary file...
I explain myself:

I have a binary file called xyz.bin
I want to get some text included in this file ("blahblah for" example)
I know it is stored betwen $0100 and $0110 in the file (for example)
Can someone help me acheiving this ?

Thanx in advance ! :)

Frederic Schmitt



Sat, 03 Jul 1999 03:00:00 GMT  
 Searching ASCII in a binary file ?

Quote:

> I have a binary file called xyz.bin
> I want to get some text included in this file ("blahblah for"
example)
> I know it is stored betwen $0100 and $0110 in the file (for example)
> Can someone help me acheiving this ?

Frederic,

You might want to try this.  I'm sure there are more elegant solutions,
but this works:

--- start of code ---
  Dim sArg As String, sFile As String
  Dim nHndl As Integer
  Dim sBuffer As String
  Dim nStart as Long, nLength as Long

  sArg = "blahblah"
  sFile = "c:\xyz.bin"
  nStart = &H100
  nLength = (&H110 - nStart) + 1
  nHndl = FreeFile

  Open sFile For Binary Access Read As #nHndl
  ' position the file pointer
  Seek #nHndl, nStart
  ' read in the string
  sBuffer = Input(nLength, #nHndl)
  If InStr(sBuffer, sArg) > 0 Then
        ' you have found your target string
  End If
--- end of code ---

Hope this helps,

Larry Fee
Systems Division, Corporate and Strategic Programs
Ministry of Health, Victoria  BC  Canada
Phone: (250) 952-1413        Fax..: (250) 952-2308



Sun, 04 Jul 1999 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. File Type (Binary or ASCII)

2. Open Binary file as Ascii

3. Write non-ASCII chars into binary file

4. File conversion - Binary to ASCII

5. Is file ASCII or WinWord (or other binary) ?

6. Inet control file transfer mode (binary/ascii)

7. How I send a binary/ascii file using winsock

8. How to write non-ASCII chars into a binary file

9. binary file search and edit

10. search in a binary file

11. Using search on binary file

12. Searching BINARY files

 

 
Powered by phpBB® Forum Software