Results 1 to 4 of 4

Thread: [Resolved] Weirdness with Binary PUT

  1. #1

    Thread Starter
    Hyperactive Member Arachnid13's Avatar
    Join Date
    Jan 2003
    Location
    England
    Posts
    327

    Resolved [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

  2. #2

    Thread Starter
    Hyperactive Member Arachnid13's Avatar
    Join Date
    Jan 2003
    Location
    England
    Posts
    327

    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

  3. #3
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    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.

  4. #4

    Thread Starter
    Hyperactive Member Arachnid13's Avatar
    Join Date
    Jan 2003
    Location
    England
    Posts
    327

    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
  •  



Click Here to Expand Forum to Full Width