|
-
Dec 13th, 2007, 10:37 AM
#1
Thread Starter
Hyperactive Member
[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?
Last edited by Arachnid13; Dec 13th, 2007 at 11:14 AM.
Reason: Resolved
Do you wake up in the morning feeling sleepy and grumpy? Then you must be Snow White
-
Dec 13th, 2007, 10:45 AM
#2
Thread Starter
Hyperactive Member
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?
Do you wake up in the morning feeling sleepy and grumpy? Then you must be Snow White
-
Dec 13th, 2007, 10:45 AM
#3
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.
Last edited by LaVolpe; Dec 13th, 2007 at 10:52 AM.
-
Dec 13th, 2007, 11:13 AM
#4
Thread Starter
Hyperactive Member
Re: Weirdness with Binary PUT
Beat you to it but thanks all the same LaVolpe
Do you wake up in the morning feeling sleepy and grumpy? Then you must be Snow White
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|