• Welcome to Valhalla Legends Archive.
 

Parsing Binary Files

Started by gameschild, January 26, 2004, 01:30 PM

Previous topic - Next topic

gameschild


Dim Buffer As String

Private Sub Form_Load()
Load_Buffer "c:\ServerTest.acc"
Dim x As Long
x = GetDWORD(Buffer)
Buffer = Right(Buffer, Len(Buffer) - 4)
x = GetDWORD(Buffer)
MsgBox x
End Sub
Public Sub Load_Buffer(FileName As String)
   On Error Resume Next
   Dim TheContents As String
   Dim fFile As Integer
   fFile = FreeFile
   Open FileName For Input As fFile
   Do
       Line Input #fFile, TheContents$
       Buffer = Buffer & TheContents$
   Loop Until EOF(fFile)
   Close fFile
End Sub

Private Function GetDWORD(data As String) As Long
Dim lReturn As Long
   Call CopyMemory(lReturn, ByVal data, 4)
   GetDWORD = lReturn
End Function


how do you read a binary file into a buffer and parse it? when i read the file in it removes the null bytes.

Grok


gameschild


Grok

Quote from: gameschild on January 26, 2004, 03:33 PM
GET what exactly?

Get the data you wish to read.  How many bytes do you want?  Create a structure of that size and use it with the GET statement.

   Dim myByte As Byte
   Get fFile, , myByte           'read next byte of file into myByte variable

Arta

Is that VB.NET or VB6? He's using VB6. (Yes, I know, I've tried.)

Grok

#5
Quote from: Arta[vL] on January 26, 2004, 07:17 PM
Is that VB.NET or VB6? He's using VB6. (Yes, I know, I've tried.)

VB6.  Question -- I always assumed that most programmers with even a couple months experience would have learned the GET statement for file handling.  When you learn any new language, isn't it natural to learn how to read and write text files, then binary files, so you'll know how when the need arises?

Banana fanna fo fanna

No.

They learn how to drag n' drop CSB.

Grok

Quote from: St0rm.iD on January 27, 2004, 05:56 PM
No.

They learn how to drag n' drop CSB.

What, if anything, does that have to do with binary file handling while learning new languages?

drivehappy

Quote from: Grok on January 27, 2004, 07:13 PM
What, if anything, does that have to do with binary file handling while learning new languages?

If you learn yourself it's more difficult to know what to do. I found that when I was learning VB I would only learn the stuff by working on a project - maybe that is how gameschild is doing it. Of course I used this method when I was about 14, so ya..

ObsidianWolf

You can use Get #1,, mybyte in vb6, I have been using get since i use ot fool around with qbasic, not sure if its older then that.

gameschild

#10
Quote
If you learn yourself it's more difficult to know what to do. I found that when I was learning VB I would only learn the stuff by working on a project - maybe that is how gameschild is doing it. Of course I used this method when I was about 14, so ya..

its more the fact that the code i had read an entire file, which was for the program i was working on, and ive never needed any such funcionality since.