Basic

Moderators: None (Apply to moderate this forum)
Number of threads: 1675
Number of posts: 4764

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
binary files? - please help! Posted by theblackfrog on 27 Jun 2001 at 1:41 PM
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

Report
Re: binary files? - please help! Posted by billywm664 on 28 Jun 2001 at 4:21 PM
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:

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


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
:


Report
Re: binary files? - please help! Posted by Pappy1942 on 29 Jun 2001 at 7:15 AM
Hi,
This worked for me.

REM ** START CODE

REM Use your file name instead of mine

OPEN "B", 1, "c:\qb45\bstmove.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.





 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.