Using Program files
Loading and Saving Program files to disk
In the lesson on Programming, we learned how to create a program using the text editor built
into the interpreter. Once the program has been written, we don't want to lose it when we
terminate our GWBasic session. We can save the program by copying the program text into a
program file onto the hard disk. This text will be in a file with a selected name and an
extension of .BAS and it will be saved into the same folder with the GWBasic.exe file that
we double clicked on to run the GWBasic interpreter.
This folder (or directory) is called the CURRENT DIRECTORY because it is the folder that
we are working in. You may have noticed that the words DIRECTORY and FOLDER are completely
interchangable. They mean exactly the same thing in our discussions. Don't permit terminology
to become confusing.
Said differently; we call the interpreter from the current directory. All files displayed
with the FILES instruction and all files SAVED with the SAVE instruction will also be in
reference to this current directory.
Go to our C:/GWBASIC directory and double click on the GWBasic.exe icon to begin this
exercise. Then type
FILES
All the files and directories in the current directory will be displayed.
Type in a single program like
10 CLS
20 PRINT " hello world "
RUN it, LIST it and play with it until you are satisfied that its a good example program.
Then save it to disk with the save instruction giving it the name EXAMPLE
SAVE "example",a
Do another FILES display with the FILES instruction
FILES
A new file will be added to the current directory name EXAMPLE.BAS
Exit the GWBasic interpreter and notice that the current directory now contains two files.
The GWBASIC.EXE file and the program file named EXAMPLE.BAS
A word of caution about using the SAVE instruction. It must be typed exactly as in the
exercise. It must be the word SAVE followed by a space to seperate the command from its
argument. The file name must be enclosed within quotation marks. Finally the comma and the
a must follow the file name. The ,a (ascii switch) directs the file be saved as an ascii
text file that can be externally edited. There will be more about this later.
Again, the
save instruction is:
SAVE "EXAMPLE",a
SAVE space quote EXAMPLE quote comma a
The complementary function to the SAVE instruction is the LOAD instruction. Open GWBasic
and ensure that the program named EXAMBLE.BAS is in the current directory. Copy the contents
of the program file into the interpreters program buffer by typing
LOAD "EXAMPLE"
LIST the program and RUN it. It is the same as when we SAVED it. It can be edited and
re-SAVED back out to the current directory if we wish.
An easier method of running a program from the current directory is to simply drag and
drop the the program file into the GWBasic.exe file. It will do the same thing as the
LOAD and RUN instruction do. It is a more "Windows" way of running a program.
Try both methods of running the program until it becomes second nature.
Externally editing the basic program file
I mentioned earlier that the file should be SAVED with the ,a switch to make it an ascii
file. This permits the program file to be edited externally from the GWBasic interpreter.
A suitable program for editing a basic file is NOTEPAD.EXE. Wordpad.exe is a .DOC file
editor that uses special characters for its advanced features. The special characters will
confuse the GWBasic interpreter. Use only plain text editors.
In summary: the program text created in the interpreter may be save to a basic source file
onto the hard disk. It may also be loaded back into the interpreter, character at a time,
as if it were entered by hand from the keyboard. Loading is essentially entering the
code from a text file rather than from the keyboard.
Submitting BASIC programs in these lessons
Programs will be given in these lessons as text. They may be copied with the copy feature
and pasted into a text file. Rename the text file extension .TXT with the extension .BAS
to make it a BASIC program source file. These program files can be run directly with the
GWBasic interpreter by using the LOAD instruction from the interpreter or by dragging and
dropping the program file into the GWBasic interpreter's icon. This convention makes it
very easy to send and recieve basic programs through e-mails.
_________ Happy Hacking ___________