[Resolved] Weirdness with Binary PUT
Take a look at this, make a new project and stick this in the form_load:
Code:
Open "C:\bla.txt" For Binary As #1
Put #1, 1, Space(4096)
Close #1
Msgbox FileLen("C:\bla.txt")
Seeing as you just wrote 4096 space characters into the file you would expect the length to be 4096... however the file has a length of 4100! Can anyone explain this?
Re: Weirdness with Binary PUT
Well i've found what causes it... but I still don't understand why, it only does it if you're writing a variant datatype to the file, meaning if you use:
Put #1, 1, CStr(Space(4096))
then it puts the spaces in correctly.. so I guess is it some kind of header for the variant type?
Re: Weirdness with Binary PUT
The 1st 4 bytes of the file, I believe, is the VarType. This is because you are writing a variant to the binary file. To write a String to the file use Space$(4096) << notice the $
Edited: FYI, the 1st 4 bytes are: VarType (vbString) are 2 bytes, string length, 2 bytes.
Re: Weirdness with Binary PUT
Beat you to it but thanks all the same LaVolpe :)