Valhalla Legends Archive

Programming => General Programming => Visual Basic Programming => Topic started by: gameschild on January 26, 2004, 01:30 PM

Title: Parsing Binary Files
Post by: gameschild on January 26, 2004, 01:30 PM

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.
Title: Re:Parsing Binary Files
Post by: Grok on January 26, 2004, 01:56 PM
GET
Title: Re:Parsing Binary Files
Post by: gameschild on January 26, 2004, 03:33 PM
GET what exactly?
Title: Re:Parsing Binary Files
Post by: Grok on January 26, 2004, 03:57 PM
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
Title: Re:Parsing Binary Files
Post by: Arta on January 26, 2004, 07:17 PM
Is that VB.NET or VB6? He's using VB6. (Yes, I know, I've tried.)
Title: Re:Parsing Binary Files
Post by: Grok on January 26, 2004, 07:28 PM
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?
Title: Re:Parsing Binary Files
Post by: Banana fanna fo fanna on January 27, 2004, 05:56 PM
No.

They learn how to drag n' drop CSB.
Title: Re:Parsing Binary Files
Post by: Grok on January 27, 2004, 07:13 PM
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?
Title: Re:Parsing Binary Files
Post by: drivehappy on January 27, 2004, 11:35 PM
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..
Title: Re:Parsing Binary Files
Post by: ObsidianWolf on January 28, 2004, 04:00 PM
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.
Title: Re:Parsing Binary Files
Post by: gameschild on February 05, 2004, 03:59 PM
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.