Results 1 to 8 of 8

Thread: strings in binary files

  1. #1

    Thread Starter
    Addicted Member DarkMoose's Avatar
    Join Date
    Jul 2000
    Location
    in a box
    Posts
    185

    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 :(
    To understand recursion, one must first understand the concept of recursion.

  2. #2

    Thread Starter
    Addicted Member DarkMoose's Avatar
    Join Date
    Jul 2000
    Location
    in a box
    Posts
    185
    oops, i meant to post this in the general forum o.o Oh well, the code is for my map editor so.. :D
    To understand recursion, one must first understand the concept of recursion.

  3. #3
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    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.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  4. #4

    Thread Starter
    Addicted Member DarkMoose's Avatar
    Join Date
    Jul 2000
    Location
    in a box
    Posts
    185
    no, that's not the problem. doesnt work when i close and re-open either
    To understand recursion, one must first understand the concept of recursion.

  5. #5
    Hyperactive Member
    Join Date
    Feb 2002
    Posts
    261
    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!

  6. #6

    Thread Starter
    Addicted Member DarkMoose's Avatar
    Join Date
    Jul 2000
    Location
    in a box
    Posts
    185
    how do you use this to write binary files?
    To understand recursion, one must first understand the concept of recursion.

  7. #7
    Frenzied Member
    Join Date
    Jul 2002
    Posts
    1,370
    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

  8. #8
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359
    'Hu Flung Dung' - The FileSystemObject is anything but efficient.
    It is a load of extra overhead for completing simple File IO operations.
    Microsoft MVP : Visual Developer - Visual Basic [2004-2005]

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