writing into buffer

I want to read a file in binary mode byte by byte using get and later I want to write the entire file into a buffer so that I can fill the content of the buffer to a variable which I can make use to transfer the file through some protocol.

Briefly I want to read the file and write the content using put to a buffer instead of writing to a disk file.

Can anybody help me out with some sample code.
Who is Participating?

Improve company productivity with a Business Account.Sign Up

cymbolicConnect With a Mentor Commented:
Basic binary file i/o to read a file would be:
dim x$, l&,y$
open "SomeFileName" for binary as #1
x$=space$(1)  'set input buffer
l&=lof(1)   'get length of file in l&
 get #1,,x$   'get one byte
 if <some condition you check for> then
   y$=y$+x$  'make big buffer
loop until <some condition you need> or l&=0
close #1

Of course if you know how much you need ahead of time, just set x$ to be space$(??) and one get will bring it all in.  If the file is small, you can set x$ to be space$(lof(1)) and read it all in in one big gulp.   Then you can interate through the input buffer x$ and check each character using either the asc or mid$ functions to check for values, then truncate x$ where ever you desire.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.