Valhalla Legends Forums Archive | Visual Basic Programming | Parsing Binary Files

AuthorMessageTime
gameschild
[code]
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
[/code]

how do you read a binary file into a buffer and parse it? when i read the file in it removes the null bytes.
January 26, 2004, 7:30 PM
Grok
GET
January 26, 2004, 7:56 PM
gameschild
GET what exactly?
January 26, 2004, 9:33 PM
Grok
[quote author=gameschild link=board=31;threadid=4916;start=0#msg41226 date=1075152800]
GET what exactly?
[/quote]

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.

[code] Dim myByte As Byte
Get fFile, , myByte 'read next byte of file into myByte variable[/code]
January 26, 2004, 9:57 PM
Arta
Is that VB.NET or VB6? He's using VB6. (Yes, I know, I've tried.)
January 27, 2004, 1:17 AM
Grok
[quote author=Arta[vL] link=board=31;threadid=4916;start=0#msg41264 date=1075166244]
Is that VB.NET or VB6? He's using VB6. (Yes, I know, I've tried.)
[/quote]

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?
January 27, 2004, 1:28 AM
St0rm.iD
No.

They learn how to drag n' drop CSB.
January 27, 2004, 11:56 PM
Grok
[quote author=St0rm.iD link=board=31;threadid=4916;start=0#msg41413 date=1075247794]
No.

They learn how to drag n' drop CSB.
[/quote]

What, if anything, does that have to do with binary file handling while learning new languages?
January 28, 2004, 1:13 AM
drivehappy
[quote author=Grok link=board=31;threadid=4916;start=0#msg41422 date=1075252393]
What, if anything, does that have to do with binary file handling while learning new languages?
[/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..
January 28, 2004, 5:35 AM
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.
January 28, 2004, 10:00 PM
gameschild
[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..
[/quote]

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.
February 5, 2004, 9:59 PM

Search