Skip to main content
gamedev.net
🔒 Locked

Binary file access in VB6

Started by NewDeal 2 replies 4.1k views
Original Post
NewDeal
NewDeal
I''m pretty much a rookie when it comes to VB so please forgive my ignorance. I''m looking for a fast way of accessing binary files using VB 6.0. I hoping that somebody might point me in the right direction (a tutorial or a brief explanation would be perfect) Thanks in advance
NewDeal
NewDeal
Hmm well... I got something working using Open, Close, Put, Get etc. I find it hard to believe that this is be best method... It reminds me of QBasic

Wyrframe
Wyrframe

Public Type CharStartPos
xPos As Single
yPos As Single
zPos As Single
End Type

Dim myInt As Integer
Dim myStr As String * 32
Dim myPos As CharStartPos

Dim fHandle As Integer
Dim fPos As Long

fHandle = FreeFile
fPos = 1
Open "file.name" For Binary As #fHandle
Get #fHandle, fPos, myInt
fPos = fPos + Len(myInt)
'' Len(var) will return the size, in bytes, of any variable.
Get #fHandle, fPos, myStr
'' Only fixed-length strings can be read automatically. For
'' variable-lenth, you''ll have to read it in character by
'' character, using a String * 1
fPos = fPos + Len(myStr)
'' Don''t just add the length of the string; the system might
'' be using double-byte characters.
Get #fHandle, fPos, myPos
fPos = fPos + Len(myPos)
Close #fHandle


You can do random-access, using Put instead of Get at any time. You can read or write to anywhere (first byte in file is byte 1), you don''t need to read in linear order, like I did above.

Anything else you need to ask, just ask!
RIP GameDev.net: launched 2 unusably-broken forum engines in as many years, and now has ceased operating as a forum at all, happy to remain naught but an advertising platform with an attached social media presense, headed by a staff who by their own admission have no idea what their userbase wants or expects.Here's to the good times; shame they exist in the past.
prh99
prh99
quote:
Original post by NewDeal
I''m pretty much a rookie when it comes to VB so please forgive my ignorance.

I''m looking for a fast way of accessing binary files using VB 6.0. I hoping that somebody might point me in the right direction (a tutorial or a brief explanation would be perfect)

Thanks in advance




Short of writing a DLL or OCX in another language (like C\C++ with asm) I think your pretty well stuck using something like this: Open filename for Binary as #1.

Patrick

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.