Writing Text Data To A File
In Pro-SiMPLE, all disk files are accessed through "Channels." There are seven channels (designated by the letters A-G) available for use. To create a particular output file you must first open one of the seven channels and specify the name (or path) to the file that you wish to create. You can then begin writing output to the file. When you are finished, you should close the channel so that it knows not to expect any more data.
The following short example program will output 3 lines of text to a file
named myfile.txt in the current project:
open a ("write myfile.txt")
write line a ("This is just some text.")
write line a ("And this is even more text.")
write line a ("I think I'll stop now.")
close a
(If you run this program, you will notice that the
word MYFILE appears in yellow in your "list of SiMPLE programs"
box on the black screen. That's because program source listings are merely text
files, and SiMPLE thinks that you've just written a new program
named MYFILE !)
The program first invokes the system library's opena task to assign an output file named myfile.txt to channel A and open it for writing. (We could have used any of the seven channels.) The program then invokes the writelinea task 3 times to output 3 lines of text. And finally, the closea task is invoked to close the channel.
Another Way Of Doing It
An alternate (but less general) way of having your program generate a text file
is to invoke SiMPLE's Output task with the "Output Mode" set
to 2. [Output Mode 1 (the default) directs all of Output's
output to the screen. Mode 2 directs it to a file named "OUTPUT" in
the current project. Mode 3 directs it to both places.]:
output mode (2)
output ("This is just some text.")
output ("And this is even more text.")
output ("I think I'll stop now.")
(To view the "OUTPUT" file that is generated, simply
type EDIT OUTPUT on the command line.)
[
Webmaster |
FAQ's |
Home Page |
Contact Us ]