-
strings in binary files
is there any reason why i can't use 'Get' to pull a string variable off of a binary file? Or maybe I'm just doing it wrong...
Code:
Dim s As String
Open "c:\windows\desktop\file1.dat" For Binary As #1
Put #1, 1, "chicken!"
Get #1, 1, s
Close
MsgBox s
the message box should display "chicken!" however I see nothing :(
-
oops, i meant to post this in the general forum o.o Oh well, the code is for my map editor so.. :D
-
If you closed, then reopened before the Get statement it would work, I think. If this works, it's because VB saves the data at the Close statement. I can't think of anything else, other than the fact that Get and Put get data from the current part of the stream, but I think you got that already with the 1, 1.
-
no, that's not the problem. doesnt work when i close and re-open either
-
I've always hated using the 'Open' statement! The FileSystemObject is a lot more efficient and easier to use (just import the 'Microsoft Scripting Runtime' reference). Its perfect for file manipulation, and reading/writing binary and plain-text files!
-
how do you use this to write binary files?
-
Try:
Code:
Dim s As String
Open "c:\windows\desktop\file1.dat" For Binary As #1
Put #1,, "chicken!"
s=Space(len("chicken!"))
Seek #1, 1
Get #1, , s
Close #1
MsgBox s
-
'Hu Flung Dung' - The FileSystemObject is anything but efficient.
It is a load of extra overhead for completing simple File IO operations.