Original Post
🔒 Locked
Binary file access in VB6
Advertisement
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!
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.
Topic Locked
This topic has been locked by a moderator. New replies are not allowed.
Sign in to reply to this topic.
Advertisement