
Opening .txt file in BASIC
Quote:
>drawing. However, I seem to be unable to open a simple text file
>within a BASIC program. It's pretty irritating consider all the
>knowledge in BASIC I presumed I had. Any help would be greatly
You don't say if you want to read from the file or write to it.
To read data from the file try:
OPEN "myfile.txt" for input as #1
If you use the exact syntax shown above then to read from the file you
would use something like (the method of inputting depends strongly on the
contents of the file and what you want to do with it ;-) :
INPUT #1, val1,val2,val3
The above example would work as you might expect if the file contained rows
of 3 numbers.
The "#1" refers to the number you will use in your program to refer to the
file once you open it.
To write to the file the "open" syntax is:
OPEN "myfile.txt" for output as #1
When you do this it erases any prior contents of the file "myfile.txt" so
be careful!
To write to it one way (again the method you choose depends on what your
desired end result is) is:
PRINT #1, val1,val2,val3