Open the program and you get the program version and memory free, on the bottom are numbers and commands. The numbers are F keys, like 1 is F1, list.
10 REM GWBASIC program 1
GWBASIC is a line number BASIC program which means each line has to have a number. Here's an example of a simple GWBASIC program.
20 REM 6-15-01
30 PRINT "Hello, what is your name?"
40 INPUT n$
50 PRINT "Good day, "n$
60 PRINT DATE$
70 PRINT TIME$
80 END
Type that in and then run the program. You can run the program by typing RUN and enter of press F2.
Hello, what is your name?
If you copied this right you should get this:
?_
Ok the ?_ is the prompt you get. Now you (the user) can input information with the keyboard. Type your name like it asks, then press Enter.
Hello, what is your name?
?DuckTape
Good day, DuckTape
06-15-01
15:31:59
Ok
After you input the data and pressed enter, you recieved the rest of the output from the program. What the code told GW-BASIC to do was to print on the screen Good day, and then print on the screen what you typed in. After that, the code said to print the date and time and then end.
There is so much more you can do with GW-BASIC, all of which
can't be explained here, but I will explain housekeeping, arithmetic, program
flow, program control, file and devive I/O (input/output), and many statements
and functions. This will give you a solid knowledge of the GW-BASIC language.
Let's start off with the basic housekeeping. Setting the
date and time in GW-BASIC is simple, type in TIME$ = "9:05" for 9:05 am, for 9:05
pm, type in TIME$ = "21:05" the clock is set on military time. To set the date
type DATE$ = "12/31/01"
PRINT TIME$
When you are writing a program dont forget to number each
line! I usually go by 10s that way if i forget a line between 20 and 30, i can
type a new line 21 that will show up after line 20 and before line 30. There is
an auto fuinction you can use to automatically number your lines. Here's the syntax:
Variables are names which store data. An example you already
know is DATE$. DATE$ stores the data such as 12-31-01. The first little program
had a variable, n$ which held whatever the use inputs, in the example case, it
was DuckTape. GW-BASIC has some keywords that can't be used as variables like
TIME$, DATE$, NAME$, etc. Just use something easy as variables like n$. A variable
has a label and then a designation. Ex: asdf$, asdf is the label and $ is the
designation. Here are some designations:
Program Flow. Here's where we get into commands, statements
and such.
To print out the date of time type in PRINT DATE$ (or TIME$) and press enter,
you should get something like this:
21:05
Ok
AUTO 100, 10 This means to start the line numbering with 100 and increment by
10, you can place any positive integer in both spots. AUTO by itself will start
the numbering at 10 and increment by 10 (what i use).
When you start typing away and have a program finished and you want to see the
code in order, type LIST. Here's the syntax for LIST:
LIST 120-230 This lists lines 120 through 230
LIST -300 This lists all lines from beginning of the program to line 300
LIST 500- This lists line 500 through the last line of the program
LIST 412 This lists line 412, if it exists
I have come a cross one problem with LIST, when the program becomes too large
and the list exceeds the screen, you can't see some of the lines, I dont know
how to correct this yet, if you do please email me
Moving on, we come to saving and loading a progam. By default, GW-BASIC saves
its files with the .BAS extention, which causes conflicts with MS Visual Basic,
but anyway here's how to save a program:
SAVE "prog1" This saves a file to the drive and directory that GW-BASIC itself
is in, the file will be prog1.bas
SAVE "A:\prog2" This saves prog2.bas to the A:\ drive
SAVE "prog3.dat" This saves prog3.dat to the drive and directory GW-BASIC is in
You can press F4 to get SAVE to come up
That's it for saving a file, now the syntax for loading a file:
LOAD "prog1" This loads prog1.bas from the drive and directory that GW-BASIC is
in
LOAD "A:\prog3.dat" This loads prog3.dat from the A:\ drive
LOAD "A:\prog2" This loads prog2.bas from the a:\ drive
You can press F3 to get LOAD to come up
As i've said before, RUN will run the program, or press F2
To change what a line says, type the line number and then the new commands, then
list that line number and it will be changed. To add lines, like i said, use large
increments and type in a line number in between.
That's about it for housekeeping, now lets get into the program controls.
$ ---- This is a string value. Ex: asdf$ can hold a vaule like "John Doe"
% ---- This is an integer from -32768 to +32767. Ex: asdf% vaule of "4732"
! ----- Single precision numbers. Ex: 56.4!, -6.435412!. The limit is 7 digits
# ---- Double precision numbers. Ex: 3.1415927456732451#, 143.6#. The limit is
17 digits.
The math get complicated with the single and double precision numbers, its covered
in the Arithmetic section.
You can assign values to variables like this:
A$ = Mary Jane
LET QWE = 52
Whenever A$ is called, the value it returns is "Mary Jane".
QWE will have a value of 52.
FOR and NEXT Statements. The FOR statement uses a variable to tell the beginning
and end of a loop. The statements that are executed by a FOR NEXT loop are written
in between the FOR and NEXT. Each FOR statement has to have a NEXT to accompy
it. Here's the syntax for FOR
FOR x = y TO z
x is a numberic variable, y is a numeric expression that is the first value of
the variable x, and z is the final value of the variable z. It sounds confusing
but it might help to see an example:
10 FOR ascii = 33 TO 122
20 PRINT CHR$(ascii); " ";asc11
30 NEXT ascii
This program uses FOR NEXT and displays ASCII codes 33 through 122. I hope this
helps you understand the FOR NEXT loops.