Solved

writing into buffer

Posted on 1998-08-11
1
277 Views
Last Modified: 2010-04-30
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.
0
Comment
Question by:lesa
1 Comment
 
LVL 9

Accepted Solution

by:
cymbolic earned 10 total points
ID: 1468556
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&
do
 get #1,,x$   'get one byte
 l&=l&-1
 if <some condition you check for> then
   y$=y$+x$  'make big buffer
 endif
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.
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question