Subj:	  iVe   APi Programming Help #12  By:  JeR
Date:	96-01-14 16:15:09 EST
From:	DiVe PiE
To:	DiVe PiE


-----------------
Forwarded Message:
Subj:	</=====-DiVe-=====\> NewsLeTTeR #11  By:  JeR
Date:	96-01-14 00:27:29 EST
From:	DiVe Q JeR
To:	DiVe Q JeR, DiVe PiE

                                                 Input/Output

I/O seems to be a problem that I have been asked about many times, so I will
try and answer as many I/O questions as I can here.

I am dividing the sections up into how you can read and write from a File...


Output

If you open a file for output, it is a standard text file that writes over
any data that is already there.  For more info, see Append.


Append

This opens a file as a standard ascii file as well, put it only adds info to
the file.  To write to this type of file you would do it like the following
example...

Print #File, StringBuffer

Where StringBuffer is a variable to write to the file.

General Information:
When you want to open a file, there you open it as an integer, and a lot of
applications will open a file as 1, but there could be another application
already using that file, so to avoid this you would do something like this:

Dim File as Integer
File = FreeFile
Open "Stuff.Foo" For Append As #File

Also, to close a file, you simply say "Close #File" where File is the number
of the File, and that is what you wouls use if you opened the file using
FreeFile.


Input

When you want to get info from an ascii file, you will want to use Input to
get data from it.  The way to do so is like this...

Line Input #File, Buffer


Binary

When dealing with a binary file, you can read and write, all without having
to open and close it as different types.  When it writes to a file, it does
not use line breaks, it writes it as 1 long string.  You can move to where
you want to read or write from in the file with the "Seek" function.  Also
keep in mind, whether you read or write to a file, it always moves the "Seek"
to the end of where you last read or wrote.  When opening a File for binary
access, you must specify a buffer to load the file, which is what the "Len ="
is for at the end of the opening line for a binary file.  Tip:  It is a good
idea when you are using binary files to store info, is to break up chunks of
information with either very low or high ansi characters, so when reading the
file you know where chunks of info start and stop.  Here is an example...

File = FreeFile
Open "Stuff.Foo" For Binary As #File Len = 3000
Get #File, , Buffer1
a = Instr(Buffer1, Chr$(240))
Buffer1 = Mid$(Buffer1, 1, a - 1)
Seek #File, Len(Buffer1)
Put #File, ,Buffer1
Close #File

This example will read from a File into a Buffer, then it will write back to
it.  It really does nothing, but it shows you how you could use it.


Note:

When working with files, make sure you do not try and read past the end of a
file, you can tell if you are at the end of a file by using EOF, you can do
it like so...

If EOF(File) Then Exit Sub
Line Input #File, Buffer

