binary files? - please help! - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

binary files? - please help!

theblackfrogtheblackfrog Posts: 1Member
yo, i need to access binary files - read and write to them and i use 'open "file.bin" for binary as #1' and then try using 'get #1,1,n' and all i get is zeros and when i use a string as n i just get nulls - i dont know what im doing wrong. please help! i need a tutorial on read/write with binary files or something - thanks all who read this and big thanks to all who help

-The Black Frog

Comments

  • billywm664billywm664 Posts: 176Member
    I'm not sure why this works and nothing else, but it does:
    Get #1,1,n$

    And somewhere in your program before that put
    n$ = space$(x)

    where x is however many bytes you want to read at once. Basically, it will fill up the whole string with the proper records from file. You can use this to your advantage actually. I use this to make fast file access routines, since a string can be 65536 characters, you can read and write in 64KB chunks!

    Use the same method to write binary files. For example, if you wanted to put "SomeMessage" 20 times into a new file, do like so:

    [code]
    n$ = "SomeMessage"
    open "file.bin" for binary as #1
    For a = 1 to 20*len(n$) step len(n$)
    put #1, a, n$
    next a
    [/code]

    Well, I hope that answers it.

    : yo, i need to access binary files - read and write to them and i use 'open "file.bin" for binary as #1' and then try using 'get #1,1,n' and all i get is zeros and when i use a string as n i just get nulls - i dont know what im doing wrong. please help! i need a tutorial on read/write with binary files or something - thanks all who read this and big thanks to all who help
    :
    : -The Black Frog
    :


  • Pappy1942Pappy1942 Posts: 46Member
    Hi,
    This worked for me.

    REM ** START CODE

    REM Use your file name instead of mine

    OPEN "B", 1, "c:qb45stmove.exe"

    k = 0
    WHILE NOT EOF(1)
    a$ = INPUT$(1, 1)
    k = k + 1
    WEND
    REM k = the number of bytes read
    PRINT k
    CLOSE 1

    REM ** END CODE

    Hope this helps.



    Pappy
    You learn something everyday.


Sign In or Register to comment.