Sei sulla pagina 1di 61

QBASIC Programming for Kids

by Ted Felix
Translation: DAMDeger (Damian Gawrych), November 2006 - January 2007
Updated: April 2007


Introduction
Introduction for parents and teachers
1 - Getting Started
Entrance to DOS Start QBASIC Exit back
2 - PRINT
Screen QBASIC QBASIC Editor Your first program
Start your program. PRINT
3 - CLS
4 - DO ... LOOP
5 - INPUT
What is "$ name"? INPUT PRINT variables and
variables
6 - IF ... THEN
7 - Numbers
Variables and mathematics Expressions
8 - Saving to disk
Saving to a floppy disk from the floppy Charging
Saving to your hard disk Create your own subdirectory
Create a folder in Windows 95 Save to folder Booting
from hard disk
9 - SELECT CASE
10 - Equations
11 - Random Numbers
RANDOMIZE TIMER Roll the Dice PRINT as such
12 - The Oracle
13 - DO ... WHILE
14 - OR and LEFT $
15 - COLOR
16 - FOR ... NEXT
17 - Sound
18 - LOCATE
19 - WIDTH
20 - CHR $
21 - Graphics
SCREEN DRAW LINE Rectangle CIRCLE
PAINT
22 - INKEY $
22.5 - String Functions
Concatenation $ LEFT () and RIGHT $ () MID
$ () LCASE $ () and UCASE $ () STRING $ ()
and SPACE $ () LEN () CHR $ () and ASC ()
INSTR ()
23 - Comments and constant
24 - Sub-Procedures (SUBs)
Arguments Scope Global data Object-oriented
programming Static Features DECLARE
25 - Data Structures
Built-in Types Variable single-precision String
variables Variables Long integer integer
variables double precision Boards TYPE
Database
25.5 - Type Conversion
STR $ () and VAL ()
25.75 - PRINT USING
25.9 - DATA and READ
RESTORE Loading the database
26 - Reading and Writing Files
Save the file OPEN, WRITE, and CLOSE
Reading from a file Keeping a log Error
handling for file Random I / O
27 - Example programs
Appendix A - Finding and installing
QBASIC
On the Internet Windows 95 DOS or Windows?
MS-DOS Windows Explorer Differences
Windows 98 SE and Windows XP
Books about QBASIC
English-Polish Dictionary



Introduction
Probably you use computers for gaming and writing student essays. Much more fun to
create your own games for the PC. This manual will help you get started using QBASIC.
QBASIC is a programming language. With such a language can tell the computer what you
want it done. It's pretty much like giving someone directions on how to get to the house. The
computer performs a step-by-step and doing exactly what he said. Programming the
computer, you can solve math problems, create images and music, and even create new
games. All this in front of you.
The best way to start with this book is to enter into a number of small computer programs
that you can find in each of the chapters. You may want to start first directly from Chapter 1
Adults can help you get through it quickly. Then change the programs do what you want
them to do. Soon you'll be writing your own programs.

Introduction for parents and teachers
Children love computers. They also like to create and have control over the world around
them. The computer will do whatever he tells you. This may at first did not look that way,
but it's true.
When I was a kid, we all had the "old BASIC". He had numbered lines and did not teach
good structured programming habits. QBASIC is a much better tool. With the information
gained from this book, one can turn to a more advanced QBASIC book (if you can find one).
After becoming proficient in QBASIC can move on to more powerful languages such as
Visual Basic, Java, C, or C + +. I would suggest a following course of study:
Logo - Teaches FORWARD, LEFT, RIGHT, TO REPEAT. (Forward, left, right,
repeat). It shows the basics of programming. You can through all this the children
step by step. You'll be surprised at how much they learn. Younger children may have
a lot of fun with the logo. Just do not get too deep; stay with the assurance that it is
funny.
QBASIC - is more conventional than the Logo programming language, so before
getting too deep into Logo is a good idea to switch to QBASIC. Children will be
resistant for two reasons: there is no longer a turtle (DRAW is similar - see. Chapter
on graphics), and by the fact that it is a new language. But the way trough through it.
You can teach the basics of QBASIC interactively, but at some point you have to
leave them out of this book, and let them type in the examples just to their questions.
Visual Basic - All skills learned in QBASIC transfer nicely to Visual Basic. Here
children can eventually learn to do real programs for Windows. Visual Basic also
includes elements of object-oriented programming, which can be introduced to help
cope with larger programs. Versions of Visual Basic from 4 to 6 have different levels
of support for object-oriented programming, while Visual BASIC 7.0 (. Net) is a
complete object-oriented language.
Java - gentle introduction to the "C" and its cousins. Concepts of object-oriented
programming can be placed here or in Visual Basic. Microsoft's C # is another
alternative to Java. The big attraction is the ability to create cool applets to run on the
network.
C - As the "C" language is probably the most having too of all, you should learn it if
you are serious about a career programmer. The big plus "C" is enormous speed. Not
up to him compiled BASIC programs. When the baby starts really pushing the limits
of BASIC, make mention of the "C", that is even better. This make them very
curious.
C + + - "Better" C and object-oriented programming concepts make the C + +
language compulsory. Not to mention the fact that C + + programmers are hard to
find and very well paid. The rate of C and Java object-oriented programming power
all wrapped up into one.
Assembler - At some point you have to tell the truth about what is under the covers.
Assembler can be introduced at any time during the learning process to explain how a
computer really works. Speak of him as being even faster than C.
Of course, you can determine when your child is ready to transition from one language to
another. My rule is that QBASIC should be placed at the point where the children can teach
themselves with this manual (age 10 or 11 years). Then let them go and master it yourself.
This gives them a huge feeling of accomplishment. When you see that reach the limits of the
possibilities of language, introduce them to other languages. Jump from QBASIC to Visual
BASIC could be done, when it becomes obvious that the programs your child will benefit
from the graphical user interface (GUI). You to determine if they are already prepared for it.
If you are an elementary school teacher interested in teaching programming and software
development for children, I would suggest starting with Logo at the level of the third or
fourth grade. Then move to QBASIC for fourth, fifth, sixth, etc. ... to teach a large number of
students is always a challenge, because everyone has different abilities. Computer
programming fits into the curriculum of mathematics, for helping students become more
aware of the number and how they "work". Because learning to program in BASIC, I
understood trigonometry by seventh grade. I did it because the type of programs that I wrote,
require an understanding of trigonometry and use it. What could be better motivation for
learning? Above the sixth grade, I suppose, you can enter the Visual Basic and continue
through Java / C # up to C / C + + at the secondary level.
At age 11, I learned from a book very similar in style to this one. It was a User's TRS-80
and came up with my first personal computer - Radio Shack TRS-80. Since then I have not
stopped programming. I hope that this book will have the same effect on your kids (or maybe
even for you).

Please email me with any comments or suggestions that improve this book. My email
address:

You can find more information on my Computer Science for Kids page:
http://tedfelix.com/cs4kids - Computer Science for Kids
And in case you are looking at a mirror site, the latest version of this book is always kept
here:
http://tedfelix.com/qbasic - QBASIC Programming for Kids
I wish you and your children a lot of fun.

From the interpreter always a great advantage for Basic thought its similarity to
natural language, bordering almost with a conversation with a machine. Now,
comparing to the use of this translation mini-glossary explaining rdosw BASIC
commands, I saw for the first time, it is this MUCH and for nieotrzaskanych in English
may be similar to learning any foreign language for them to die so the main advantage
of all Basic'w . It remains to hope that at least the little ones riding characteristics of
English is becoming more and more common ...

Chapter 1 - Getting Started
Entrance to DOS
To start QBASIC, you need to get to DOS.
If you are using Windows 3.1, you need to find the "Group principal" and look for an icon
called "MS-DOS". Double-clicking on it gives the prompt " C:\WINDOWS> _ C: \
WINDOWS> _ "In the black window with white text.
In Windows 95, click "Start", "Programs", then "MS-DOS".


In Windows 98 and Windows ME, the procedure is the same as, and Windows 95
In Windows NT 4, I am convinced that it was called "command prompt". Try the steps
below for Windows 2000.
In Windows 2000, this is called "Command Prompt" and you can find it by clicking on Start,
then Programs, then Accessories and finally Command Prompt.
In Windows XP, it is called "Command Prompt" and also you can get there by clicking on
Start, then Programs, then Accessories, and Command Prompt.
You will get a black window with a flashing " C:\WINDOWS> _ C: \ WINDOWS> _ "Cursor.


You are now ready for the next step.
Start QBASIC
QBASIC might not be on your computer. Do not worry, Appendix A will show you how to
get it. At the " C:\WINDOWS> _ C: \ WINDOWS> _ "Try typing:
qbasic
and press <Enter>.


If you get a blue screen with something like "Survival Guide", you made it!


If instead you get a message like "Bad command or file name",


you need to check in Appendix A to get QBASIC installed on your machine. Do not worry,
we'll be there waiting for you.
Survival Guide?
"Survival Guide"? We will not use at the moment (though it is in English - ed. Crowd.) So
press the Esc (escape) to get a big blank blue screen.


We are now ready for programming.
Out back
If you need to leave QBASIC, you can click on "File" on QBASIC's menu and then "Exit" to
get back to DOS.


At the " C:\WINDOWS> _ C: \ WINDOWS> _ "Type:
exit
and press <Enter> to get rid of the DOS window.



Chapter 2 - PRINT
We continue
I assume that you will get acquainted with QBasic'iem from the beginning. It would not be
good if it were otherwise. So turn on your computer and keep in front of a blue screen
QBASIC. Go ahead and press the Esc key to close the welcome window ("clear this dialog
box").
Screen QBASIC
Before we begin, take a look at the screen QBASIC. At the top there is a menu that has the
following tabs: File, Edit, View, Search, Run, Debug, Options and Help.


Clicking on any of these with the additional choice.
Just below the menu is the word "Untitled". I mean, we have not given the name of the
current program. This will change when we learn to save programs. Big blue area with a
blinking cursor _ ) Is a place where we can enter our programs.
These are the most important areas that you need to know today. We will learn more about
the rest of QBASIC's screen as we go along.
QBASIC Editor
If you use a computer at school or writing essays, you will notice that most of the editing
keys (<Backspace>, <Delete>, <Insert> ...) works as always. In case you have not used them
before, here's the list:
<Backspace> - Deletes the character to the left of the cursor
<Delete> - Deletes the character under the cursor
<down <Left - Moves the cursor to the left
<down Right> - moves the cursor to the right
<Up Arrow> - moves the cursor up
<down <down> - Moves the cursor down
<Home> - Moves the cursor to the beginning of the line
<End> - Moves the cursor to the end of the line
Your first program
With the blinking cursor ( _ ) In the upper left corner of the screen, type the following:
PRINT "Welcome to QBASIC. Your wish is my command."
Make sure it looks exactly like that. Quotation marks ( " ) are very important. If you make
any mistakes, use <Backspace> to improve them.


Starting your program.
Fine, but what does this have to do? You have to run it to find out. Find the word "Run" on
QBASIC's menu at the top of the screen. Click on it. You will now see a menu of your
choice (Start, Restart and Continue). Click on Start to run your program. You can look
around the screen a bit, but you should find your message:
C: \ WINDOWS> qbasic
Welcome to QBASIC. Your wish is my command.
PRINT
PRINT prints things on the screen. Do not forget to put what you want to say in double
quotes (").
Press any key to continue?
At the bottom of the screen you'll see the message "Press any key to continue" ("Press any
key to continue"). Press <Enter> to get back to QBASIC. This is the way QBASIC to give
you enough time to see what your program did.
As a convenient shortcut, use? instead of PRINT. Try it. Press <Enter> to start writing in a
new line. This time, type:
? "Programming is fun."
and again press <Enter>.
Is not it nice? ? becomes the word PRINT. That should save us a lot of writing.
You can try to run the program a second time (remember? Click on Run, then in the Start
menu.) You should see something like this:
C: \ WINDOWS> qbasic
Welcome to QBASIC. Your wish is my command.
Welcome to QBASIC. Your wish is my command.
Programming is fun.
Learned
Screen QBASIC
Edit Keys
PRINT
Run | Home
?

Chapter 3 - CLS
Probably a little hard to find on the screen of your messages from the last program. Would
not it be nice to be able to clear all these things from the screen? The solution here is "CLS",
which comes from the Clear Screen ("Clear Screen"). You will need to put CLS at the top of
your program to clear the screen before printing anything.
Inserting a new line at the top.
To make CLS the first line of your program, follow these steps:
Press <Home> to get to the beginning of the current line.
Press <Up Arrow> once or twice to get the cursor at the top of the program.
Press <Enter> to get a new line.
Press once <Up Arrow> to place the cursor on the new line.
Type CLS
Now your program should look like this:
CLS
PRINT "Welcome to QBASIC. Your wish is my command."
PRINT "Programming is fun."
Run it. Remember - click on Run and then Start in QBASIC's menu. You can also run the
program by pressing <Shift> and holding it down while pressing <F5> (this means Shift + F5
on the menu). Another handy shortcut.
Now it is much better. The screen only those messages that should be there.
Learned
CLS
Shift + F5

Chapter 4 - DO ... LOOP
Let's start the new program. To get rid of the old program, click on "File" on QBASIC's
menu - see the File menu with New, Open ..., Save, and others. Click on "New". QBASIC
will now tell you that your current program is not saved and asks if you want to "Save it
now?" (Save it now?). Do not save it. You can always enter it again. Click on the <No>.
How to save programs, we will learn in Chapter 8
Now you should have a pure blue screen. Enter this program:
TO
PRINT "Ted was here";
LOOP
Check if you inserted a semicolon (;) at the end of the PRINT line and a space between the
word "here" and the last quotation mark. You do not have to use my name, instead put your
("Here is John", or whatever). Now run it.
DO ... LOOP
DO and LOOP will do whatever is between the DO and LOOP again and again ...
Where is the brake?
Ok, nice. HOW DO I STOP!? Press <Ctrl> (Control) and hold it down while pressing the
<Pause>. <Pause> Is usually at the top of the keyboard and is always on the right. This is
called "pressing the <Break> key." Do not worry, it does not really break your program, it
just stops it and takes you back to QBASIC. Perhaps this key should be called "brake".
(Brake - "brake", pronounced the same as the break - "break" - [Brejk]. Prov. Crowd.)
On keyboards laptops Break key can be a little harder to find. Sometimes you have to press
the "Fn" key and then the key that makes a break. Sometimes it is marked to help you find it.
You'll know where he is (experimentally) when the program stops and returns the editor.
Neatness Counts
Note that PRINT is faced with two spaces. This is called "indented" and makes the program
easier to read. You can more clearly see the beginning and the end of the DO ... LOOP.
QBASIC does not care about indentation, only people do. It is important to make your
program look nice as it could be read others.
Learned
File | New
DO ... LOOP
<Break>

Chapter 5 - INPUT
So far our programs have only talked to us. Write one that will listen. Get rid of the
previous program by clicking on File and then New on QBASIC's menu. Click on the <No>
when it asks you if you want to save the program to disk. Try this:
CLS
INPUT "Enter your name:", $ name
PRINT "Hello"; $ Name; . "How are you today?"
Do not forget the comma (,) between "Enter your name" and name $. Run it. When it asks,
type your name and then press the <Enter> key
What is "$ name"?
"$ Name" is called "variable". Being a variable means that things can change. Try to run the
program again, but this time, type the name (do not forget the key <Enter>). Indeed, the
message changes.
INPUT
INPUT $ name gets what you type on the keyboard and inserted into the variable $ name.
PRINT Name $ prints what is in the variable $ name.
Variables
Variables hold letters and numbers. The dollar sign ($) indicates that this variable can hold
letters. It is called a "string variable". Variables without a dollar sign can only store
numbers. We'll see them later.
You can call your variables as you like. Try returning to the program and change every "$
name" to "Janek $". What happens when you run it?
Another way to think of a variable is to imagine a small bucket with a name
on it. Paint on it "$ name". This is the name of the bucket (variable). Now
take a piece of paper and write your name on it and throw it into the
imaginary bucket. Now the variable $ name is in the middle of your name.
Computer variables can hold only one piece of paper (one value) at a time.

PRINT and variable
When you want to print (PRINT) what is in the variable, leave the double quotation marks
(""). This program will show you how it works:
CLS
INPUT "Enter your name:", $ name
PRINT "$ name"
PRINT Name $
The first PRINT prints screen name $. The second command PRINT prints the name you
entered.
Learned
INPUT
Variables

Chapter 6 - IF ... THEN
Let's make this last program a little smarter. I would like to recognize intruders playing in
my programs. Would not it be nice if the computer could recognize someone's name and
print a special message for him? Or maybe this:
CLS
INPUT "Enter your name:", Name $
IF Name $ = "Mike" THEN
PRINT "Go away!"
ELSE
PRINT "Hello"; $ Name; . "How are you?"
END IF
You can change the Name $ = "Mike" in the Name $ = "Joe" or whoever you want to go
away (like a brother or sister). Run the program and enter your name (I hope this is not
Jack). You should see the same message as before. Now run it again and try typing "Mike"
(or "Joe" or whatever you changed it).
"Mike" is not the same as "mike"
If the program does not tell the right person to go away, make sure you typed the name
correctly. In QBASIC, "Mike" is not the same as "mike", so if you do not type the letter, the
program will not work. Ensure that you enter the name exactly as you entered them in the
program.
IF ... THEN
The "IF .. THEN .. ELSE .. END IF" in the program checks whether the Name $ contains the
"Mike". If so, then executes the command after THEN PRINT. When the Name $ is not
"Mike", is performed after ELSE PRINT command. "END IF" (end of IF) tells QBASIC that
this is the end of the IF.
Conditions
IF ... THEN part - Name $ = "Mike" called the "condition". With numbers, you can also
check the "greater than" and "less than":
CLS
INPUT "Enter a number:", Number
IF Number <100 THEN
PRINT "Your number is less than 100"
ELSE
PRINT "Your number is greater than or equal 100"
END IF
If you want to check the "greater than", use "Number> 100". Equality works just like before,
"Number = 100". Another option is "not equal", which can be made as follows: "Number <>
100".
IF ... THEN is one of the most powerful features of QBASIC. Using IF ... THEN can make
your programs very interesting. It allows programs to make decisions and react accordingly.
Learned
IF ... THEN ... ELSE


Chapter 7 - Numbers
Computers are very good at math. Let the computer to do some math for us. Here is a
simple multiplication calculator:
CLS
INPUT "Enter first number:", A
INPUT "Enter the second number:", B
PRINT "The result is:"; A * B
If you have trouble finding an asterisk (*) on the keyboard, it is usually above the number 8
Run it and enter two numbers. It does an excellent job multiplying for you.
Variables and mathematics
A and B are variables like $ name. Unlike Name $, A and B do not have a dollar sign at the
end of their names. This is because they keep only numbers, not letters.
Star
"A * B" means "A times B". QBASIC does not use "X" for multiplication, because you
might want to have a variable called "X".
What else?
Try changing the "A * B" to "A - B" for subtraction. "A + B" will do the addition, and the
"A / B" performance division. Why "/" for division? Because there is no division sign on the
keyboard. At least I have not found.
Expressions
"A * B", "A + B", "A - B" and "A / B" are called mathematical expressions, or simply
expressions.
Learned
Variables with numbers
INPUT with numbers
Multiplication, division, addition, subtraction
Expressions

Chapter 8 - Saving to disk
Before we move to longer programs, let's see how to save our masterpieces.
Location is everything
The first thing you need to think about is where you are going to save our programs. The
two main places where we can save them, the hard disk and floppy disk. Consider both.
Saving to a floppy disk
Using a floppy is a good idea when you do not want other people looking at your programs.
The floppy disk can be removed from the computer and kept in a safe place. Floppy disks are
also good when you want to transfer programs from one computer to another.
Let's try this. Find a blank floppy disk and insert it into the floppy drive. The floppy disk
can contain anything yet, provided that it has been on it a little bit of free space. You need to
have the program appear on the screen for this to work properly. Return to the previous
chapter and type example, if you want to have something on the screen.
Click on the "File" menu in QBASIC and then "Save".
The screen displays "Save" dialog. Note that the cursor is in the box (field) called "File
Name:" ("File name:") Type this:
a: \ testsave
Watch out for the backslash (backslash, "\"). This is not the same thing as a forward slash
"/", which is on the same key as the question mark "?". QBASIC is very sensitive.
Press <Enter>. What happened? Did you hear something? Where is the "Save" dialog?
Hmmmm, let's hope it worked. How can we check? Try to load the program back to
QBASIC. Wait, he's already here. OK, so remove it and try to get out of the back of the
floppy disk. Do you remember how to get rid of the program? Note: The "File" and "New"
from the menu.
Booting from a floppy disk
Do this: Click on "File" then "Open ..." on QBASIC's menu. Now you should see the
"Open" dialog. Type this:
a:
and press <Enter> Now you should see "TESTSAVE.BAS" in the box called "Files"
("Files"). Two clicks oughta do it. Click on "TESTSAVE.BAS" and the program returns
from a floppy disk.
Saving to your hard drive
Hard drive is the most convenient place to store programs. Because it is always on your
computer, your programs are always there for you to load when you need it.
Neatness counts, again.
Hard drives usually contain much more information than a floppy disk. For this reason you
need to worry about keeping things neat. Otherwise, you will never be able to find what you
need. The best way to organize your collection programs is to put them in the "sub" or
"folder" on your hard disk.
Create your own subdirectory
Let's make a folder on your hard drive for our programs. In Windows 95 (and higher) will
need to use Windows Explorer. In Windows 3.1, we will use File Manager.
Create a folder in Windows 95
Click "Start" then "Programs" then "Windows Explorer". Now click on "File", then "New"
then "Folder" menu in Windows Explorer.
Note the words "New Folder" from the right side of the Windows Explorer.
Go ahead and type a name for the new folder, but keep it short! QBASIC is an older
program that does not handle names bigger than 8 letters or numbers. I called your
"TedPrgs" what does that mean Ted's Programs. Name your folder as you like, but no more
than 8 characters, otherwise it will look very strange in QBASIC.
Press <Enter> key to create the folder. OK, done. You will not have to do it again, unless
you want to create another folder at a later time. Go ahead and close the Windows Explorer,
go back to QBASIC.
Writing to directory
Saving to your hard drive just a little bit different from saving to a floppy disk. Program to
save you must have seen on the screen. Return to the previous chapter and type example, if
you want to have something on the screen.
Click on the "File" menu in QBASIC and then "Save".
The screen displays "Save" dialog. The cursor is in the window (field) called "File Name:"
("File name:") Type this:
c: \ TedsPrgs
Again, watch the backslash "\". Change TedsPrgs how you named your directory.
Press <Enter>. You should now see a list of programs in this directory. As yet have not
saved anything, there should not be any programs. Go ahead and type it:
testsave
and press <Enter>. Hmmm, this time you can not hear any sound. Hard drives are much
quieter than a floppy disk. Let's see if it worked properly. First, get rid of what is on the
screen, the "File" and then "New".
Booting from hard disk
It is also very similar to the way we loaded a program from a floppy disk. Click on "File"
then "Open ..." on QBASIC's menu. This will bring up a dialogue "Open". Type this:
c: \ TedsPrgs
As before, watch the backslash "\" and change "TedsPrgs" how your folder was called.
Now you should see "TESTSAVE.BAS" in the "Files". Double click on the
"TESTSAVE.BAS" to load it.
Not so bad, right? Once you figure out whether you want to save to a floppy disk or hard
disk, you need to remember only one way to save and load.
Learned
Saving to a floppy disk
Booting from a floppy disk
Creating a folder
Saving to your hard drive
Booting from hard disk

Chapter 9 - SELECT CASE
IF ... THEN ... ELSE is good if you have only two things to check. And what if you have 5
or 6 friends who can use your computer, and you want it to everyone said what else? Try
this:
CLS
INPUT "Enter your name:", Name $
SELECT CASE Name $
CASE "Ted"
PRINT "Hello, Grand Master"
CASE "Mike"
PRINT "Go away!"
CASE ELSE
PRINT "Hello"; Name $; . "How are you?"
END SELECT
Well, it was a big one. Fortunately we learned in Chapter 8, and write to the disk. Change
"Ted" and "Mike" to "Laura" and "Charles" or whatever.
SELECT CASE
SELECT CASE first checks Name $ for the "Ted". If it finds it, it does the PRINT after the
CASE "Ted". When PRINT is done, the rest of the cases CASE is lowered. Otherwise,
while we check each CASE until the CASE ELSE. If you have not found anything, what is
the CASE ELSE.
Just in case
SELECT CASE can also be used with numbers as well as letters from the chains. Here's a
quick example:
CLS
INPUT "Enter a number:", Number
SELECT CASE Number
CASE 1234
PRINT "Thank you for entering the secret number 1234"
CASE 22
PRINT "Yes, 22 is an interesting number"
CASE ELSE
PRINT "You do not know the secret number"
END SELECT
Learned
SELECT CASE

Chapter 10 - Equations
So far, only let the user fill in our variables. We can fill in the variables within our program.
Like this:
CLS
A = 1
B = 2
A $ = "Hello"
PRINT A
PRINT B
PRINT A $
"A = 1" places the value 1 in the variable A. "B = 2" places the value 2 in the variable B. A $
= "Hello" puts the string "Hello" in the variable A $. The program then prints them on the
screen to show you that they are there.
See if you can figure out what this rather clever program will do. Then type it in and run it
to see if you were right.
CLS
Count = 1
TO
PRINT Count
Count = Count + 1
LOOP
Are you right?The output go too fast? You will need to press Break to stop them. Now take a
closer look and see if you can, what is happening here.
Such a program is what we call a "counter". It counts 1, 2, 3, 4 .. until it is stopped.

Chapter 11 - Random Numbers
Random numbers are numbers that you can not predict. Throw a coin or rolling dice gives
you a random number. These numbers are very important in games and in some branches of
mathematics. Computers can generate random numbers pretty well. QBASIC's RND provides
random numbers that we can use.
RND
RND is a special function that gives us a random integer between 0 and 1 can use this in
games to make things interesting. RND is perfect for rolling the dice or a coin. First let's see
RND in action:
CLS
PRINT RND
PRINT RND
This program prints two times RND. Note that you will get two numbers that seem
unpredictable and random. But try to run the program again. You'll get the same "random"
numbers. This means that your game would be the same every time you run them.
Fortunately, there is a way to fix it.
RANDOMIZE TIMER
Using RANDOMIZE TIMER will make sure the random numbers that you get will be
different each time you run. Try this:
CLS
RANDOMIZE TIMER
PRINT RND
PRINT RND
Useful random numbers
Random numbers from between 0 and 1 are not really too useful. What if the game you need
a random number between 1 and 6, as when you roll the dice? To get something more useful,
we will use mathematics. Fortunately, computers are very good at math.
There are two problems that we must solve in order to get the results we want. The first is
enlarging the range of random numbers from 0 to 1 to 1 to 6 This is easily done:
CLS
RANDOMIZE TIMER
PRINT RND * 6 + 1
PRINT RND * 6 + 1
Multiplying by 6, increase the range of 0 to 5 by adding 1 to move the range of 1 to 6,
however, there is still a problem. All this "tail" fractional. QBASIC's INT function and can be
used to convert a decimal integer (a number without a decimal point).
CLS
RANDOMIZE TIMER
PRINT INT (RND * 6 + 1)
PRINT INT (RND * 6 + 1)
Roll the Dice
Here is a program that rolls two dice and prints the value of each of them. Variables Die1 and
Die2 are used to store the value of each die before printing. In the actual game Die1 and Die2
could be used in a clever way to change the outcome of the game.
CLS
RANDOMIZE TIMER
INPUT "Press ENTER to roll dice ...", A $
PRINT
Die1 = INT (RND * 6 + 1)
Die2 = INT (RND * 6 + 1)
PRINT "Block-1"; Die1
PRINT "Cube 2:"; Die2
PRINT as such
Note that the last line of the program was the PRINT. Do you see what she's doing? It just
prints a blank line on the screen. This can be useful for making the results look nicer in your
program.

Chapter 12 - The Oracle
Here's a cool program that uses most of what we've learned so far.
CLS
RANDOMIZE TIMER
PRINT "I'm a magic oracle."
INPUT "Think of a question and press ENTER for your answer ...", A $
PRINT
Re = INT (RND * 5 + 1)
SELECT CASE A.
CASE 1
PRINT "Yes, definitely."
CASE 2
PRINT "Ask again tomorrow."
CASE 3
PRINT "I will not tell!"
CASE 4
PRINT "That's for sure."
CASE 5
PRINT "Yes."
END SELECT
As always, go ahead and customize it. Change "I will not tell!" on "It depends ...", and you
get an oracle, which never says "No".
Adding cases
Go ahead and try to add a new prophecy. You will need to change
Re = INT (RND * 5 + 1)
on
Re = INT (RND * 6 + 1)
because now there will be 6 then you will need to add a " CASE 6 "and PRINT to print the
new prophecy.

Chapter 13 - DO ... WHILE
Earlier, in Chapter 4 we have seen DO ... LOOP loop running indefinitely. There are a
number of ways to loop stopped. One of them is to use WHILE. The next program uses
WHILE to make sure the program ran so long as Re $ contains the letter "t".
CLS
TO
INPUT "Enter first number:", A
INPUT "Enter the second number:", B
PRINT "The result is:"; A * B

INPUT "Do you want to do it again (y / n)?" Re $
LOOP WHILE Re $ = "t"
The condition on the LOOP WHILE statement is the same as the condition that we could use
the IF ... THEN. In this case, check to see if Answer $ = "t" and if so, continue the loop. If we
do not, we go out of the loop and the program ends.
You can add this feature to any program. Try to add it to Oracle.

Chapter 14 - OR and LEFT $
Our last program works great as long as the user always enters a small "t". What happens if
the user types "yes"? Because "yes" to the computer is not the same as "t" test for Re $ = "t"
fails and the program ends. Probably not a good idea. The same problem we have when a
user enters a capital "T". Try it to see what I mean.
There are a few ways to make this program more intelligent and easier to use for our users.
We could check a few ways to say "yes" using the OR ("or") , like this:
CLS
TO
INPUT "Enter first number:", A
INPUT "Enter the second number:", B
PRINT "The result is:"; A * B

INPUT "Do you want to do it again (y / n)?" Re $
LOOP WHILE Re $ = "y" OR Re $ = "T"
This version will allow the user to enter a "t" or "T" and the program will run again. We can
do even more clever by using LEFT $ like this:
CLS
TO
INPUT "Enter first number:", A
INPUT "Enter the second number:", B
PRINT "The result is:"; A * B

INPUT "Do you want to do it again (y / n)?" Re $
FirstLetter $ = LEFT $ (Answer $, 1)
LOOP WHILE FirstLetter $ = "y" OR FirstLetter $ = "T"
This version will allow the user to type "yes", "yes" or anything that starts with a "y" because
LEFT $ only look at the first letter in your answer. You can even type "here" and the program
will start up again.
This may seem to make the computer smarter, but we know what's really happening. To
prove that the computer actually is not very smart, try typing "Sure!" or "folding". He thinks,
"Sure!" to say "no", and "yellow" - "yes".
LEFT $
LEFT $ can be used to take a certain number of letters from the left side of a string variable.
As example, if we have:
A $ = "TEST"
then LEFT $ (A $, 2) will give us the "TE". LEFT $ (A $, 3) will give us "TES". The first
"parameter" you pass to LEFT $ is a string, you want to work. The second parameter passed
to the LEFT $ is the number of characters (letters) you want to get. Try a program that uses
LEFT $ in another way:
INPUT "Enter something:", A $
PRINT A $
PRINT LEFT $ (A $, 1)
PRINT LEFT $ (A $, 2)
PRINT LEFT $ (A $, 3)
This program will print the first sign of anything, then the first two characters, and then the
first three characters:
Enter something: Jack
Jacek
J
I
Jac
If you were curious, it also has QBASIC RIGHT $ (right = right) and it works exactly like
LEFT $ (). Try this:
INPUT "Enter something:", A $
PRINT A $
PRINT RIGHT $ (A $, 1)
PRINT RIGHT $ (A $, 2)
PRINT RIGHT $ (A $, 3)
Here is an example of what this program will do:
Enter something: Jack
Jacek
k
ek
cek

Chapter 15 - COLOR
Tired of all this black and white? Then the statement is for you COLOR.
CLS
COLOR 2, 0
PRINT "That's';
COLOR 3 0
PRINT "more";
COLOR 5, 0
PRINT "like it!"
Color requires two numbers. The first number is the foreground color. The second number is
the color of the background. For example, if you want to write in black and white, use the
"COLOR 0.7". All colors have their own numbers:
0 - Black (Black)
1 - Blue (Blue)
2 - Green (Green)
3 - Cyan (Cyan)
4 - Red (Red)
5 - Purple (Magenta)
6 - Yellow (Yellow)
7 - White (White)
There are also plenty of other colors. Try the numbers from 8 to 15 to see what colors you
get. Basically, if you add 8 to each of these colors, you get a lighter version of the same color.
Take the blue, which is the number 1 and add 8 - you get 9, which is light blue.
Flicker
Adding 16 to the number of color give you a blinking version. This, however, does not work
in a DOS window. Press <ALT> <ENTER> to switch to full screen mode, which will flicker.
Try this program:
CLS
COLOR 28, 0
PRINT "*** WARNING ***"
COLOR 15, 0
PRINT "Programming can be too much fun!"
Color can be used in many ways to make programs more interesting.

Chapter 16 - FOR ... NEXT
New counter
FOR ... NEXT loop is the DO ... LOOP, but a FOR ... NEXT built-in self-timer. Try this:
CLS
FOR I = 1 TO 10
PRINT AND
NEXT I
Much better than our last counter. This stops itself after the deduction to 10
Color card
Here is a program with a palette of colors, using the FOR ... NEXT loop.
CLS
FOR I = 1 TO 15
COLOR I, 0
PRINT I; "*** COLOR ***"
NEXT I
STEP
FOR ... NEXT can also "to count steps." Try this:
CLS
FOR I = 2 TO 20 STEP 2
PRINT AND
NEXT I
It will count down by twos from 2 to 20 STEP tells QBASIC, after how much to deduct. Try
to change it to count tens of from 10 to 100
FOR ... NEXT can also count backwards if you use a negative STEP:
CLS
FOR I = 10 TO 1 STEP -1
PRINT AND
SLEEP 1
NEXT I
PRINT "strike!"
"SLEEP 1" tells QBASIC to wait for one second and then continue.

Chapter 17 - Sound
If you just need a beep in your program, you can use BEEP:
CLS
INPUT "Press Enter to hear BEEP", A $
BEEP
SOUND allows you to play a "beep" and tell you how high or low it will be and how long it
will last. This program makes a 1000Hz beep for about 1 second:
SOUND 1000, 18
SOUND is good for making sound effects. Here are dropping bombs:
FOR I = 4000 TO 1000 STEP -5
SOUND I, .1
NEXT I
If you want to play a song, PLAY is exactly what you need. Try this:
PLAY "e8 d8 c8 d8 e8 e8 e4"
PLAY is like a small programming language inside of QBASIC. "E8" means "play an eighth
E". If you are familiar with sheet music, understand what it means. Here are the range:
PLAY "c8 d8 e8 f8 g8 b8 a8> c4"
The ">" ("greater than") means "take one octave higher." In PLAY a number of special
commands. See QBASIC help for a list of all of them.
PLAY and triplets
Here's a familiar tune that uses a trick to do triplets.
PLAY "<d8d8d8 T180 T120 g2> d2"
PLAY "c8 T180 T120 <b8a8> g2d4"
PLAY "c8 T180 T120 <b8a8> g2d4"
PLAY "<b8> c8 c8 T180 T120 <a2>"
Since PLAY does not do triplets, you have to modify the pace to get the right rhythm. PLAY
starts in the default rate "T120", which means 120 quarters (quarter notes) per minute. In the
above tunes, switch them on the T180, which is the rate of triplet for the T120. Multiplying
our pace by 1.5 we obtain the rate of triplet. When the triplet is ready, we switch back to a
normal pace. In the example above you can see that switching back and forth between the
main tempo (T120) and the rate of triplet (T180) several times when you need to.
As usual, there is more than one way to do triplets. Triplet eighth notes can be replaced with
twelves, as here:
PLAY "<d12d12d12g2> d2"
PLAY "c12 <b12a12> g2d4"
PLAY "c12 <b12a12> g2d4"
PLAY "c12 c12 <b12> <a2>"
Using this technique, sixteen become 24, etc. .. Just multiply the length of the notes for 1.5,
instead of changing the tempo.
Each of these techniques has advantages and disadvantages. Technique change of pace takes
up more space, but the notes retain their value. The technique of twelves is more compact,
but not so easy to understand. Which one you follow is up to you. Just make sure that another
person reading your code will know what you are doing. Comments are a good idea.



Chapter 18 - LOCATE
LOCATE allows you to print at a specific location on the screen.
CLS
LOCATE 5, 10
PRINT "Here"
LOCATE 20, 70
PRINT "Tam"
The two numbers after LOCATE are the coordinates of the place where it will be printed.
Just like in math, these numbers give the row and column. The first number in the LOCATE
is a poem, or how far down the screen printing is about to begin. The second number is the
column, or how it is to be far to the right.
Use some random numbers and COLOR and LOCATE to make a more interesting version of
our first program with a loop:
CLS
TO
Row = INT (RND * 23 + 1)
Column = INT (RND * 79 + 1)
LOCATE Row, Column
Color1 = INT (RND * 15 + 1)
COLOR Color1 0
PRINT "Ted was here!"
LOOP
Kind of messy, but interesting.
Or maybe the clock?
CLS
TO
LOCATE 1, 1
PRINT TIME $
SLEEP 1
LOOP
TIME $ is a special variable that contains the current time. To stop, press the Break.

Chapter 19 - WIDTH
Use WIDTH 40 for big text. It changes the entire screen in wide text mode. Use WIDTH 80
to return to normal text size.
SCREEN 0
WIDTH 40
CLS
PRINT "Oh, this is great!"
INPUT "Press <Enter> to go back", A $
WIDTH 80
PRINT "And that's it!"
Unfortunately, you will not see the big text in the window. You will have to press <Alt> -
<Enter> to switch to full screen mode. Check the press <Alt> - <Enter> again to return to the
window.

Chapter 20 - CHR $
There are a lot of special symbols and characters that can be displayed, and they are not on
the keyboard. Try this:
CLS
PRINT CHR $ (1); CHR $ (2)
Prints a pair of smiley faces. There are plenty of other characters. This program will show
you many of them, although not all:
CLS
FOR I = 32 to 255
PRINT I; CHR $ (I); "";
NEXT I

Chapter 21 - Stock
So far, we had to deal only with text (words and numbers). How do you make pictures in
QBASIC? First you have to use SCREEN to change from text mode to graphic design.
SCREEN
SCREEN (screen, stage) allows you to select the screen "graphic" instead of "text", which we
have used so far. This will allow you to draw pictures. In the next program we will use the
DRAW (draw = draw) to draw a square on the screen in graphics mode SCREEN 12
SCREEN 12
CLS
DRAW "D100 R100 U100 L100"
There are many other SCREEN numbers you can use, but 12 is probably the easiest to work
with. It gives you a lot of space and color numbers are familiar. QBASIC Help and explains
all possible values of SCREEN. You can always try it and see what happens.
DRAW
DRAW is something like "turtle" in the Logo programming language. With DRAW, you can
move around the screen and draw lines along the way. In the example above, we used the
following DRAW commands:
D100 - Go Down ( D own) 100 units
R100 - Go right ( R ight) 100 units
U100 - Go Up ( U p) 100 units
L100 - Go left ( L eft) 100 units
DRAW can do much more than that. It's like PLAY; is a small programming language inside
of QBASIC. Refer to the Help QBASIC after a complete description of everything that can
DRAW. Here's a filled square:
SCREEN 12
CLS
DRAW "C15 D100 R100 U100 L100 BF1 P15, 15"
"C15" sets the color to bright white. "BF1" moves to the square, then "P15, 15" fills it with
bright. And finally, something very similar to the logo:
SCREEN 12
CLS
FOR I = 0 TO 360 STEP 10
DRAW "D100 R100 U100 L100 TA" + STR $ (I)
NEXT I
"TA" means the rotation of a certain angle. STR $ converts the value of the variable and a
string. It lets DRAW turn to the angle of the variable I. This is not as easy as Logo, but still
impressive.
LINE
QBASIC can also draw using a coordinate system. It's like drawing graphs on graph paper.
Try this:
SCREEN 12
CLS
LINE (0, 0) - (320, 240), 15
LINE lets you draw a line between two points. Points are defined by coordinates (x, y). You
could see it, learning about graphs in math. In QBASIC, the coordinates are almost the same.
The only different thing is to coordinate Y. In QBASIC, the Y coordinate is upside down. "0"
is at the top and the growing number of run down the screen.
"LINE (0, 0) - (320, 240), 15" draws a line ends at (0, 0), which is the upper-left corner of the
screen. The last number is the number of color (15 - bright white).
Rectangle
By adding a "B" at the end of the LINE command, you can draw a rectangle. Try this:
SCREEN 12
CLS
LINE (0, 0) - (320, 240) 15, B
The first pair of coordinates is the upper left corner, and the second pair - lower right.
Try "BF" instead of "B". Interesting?
CIRCLE
QBASIC can also draw circles (circles) using the CIRCLE command:
SCREEN 12
CLS
CIRCLE (320, 240), 100, 15
Coordinates (320, 240) tells the computer where to place the center of the circle. "100" is the
radius, how big will the circle. "15" is the number of color (bright white again).
PAINT
Note that the circle was not filled. LINE has a "BF" option which let us fill-drawn rectangles.
CIRCLE is no such option, so we will use PAINT:
SCREEN 12
CLS
CIRCLE (320, 240), 100, 15
PAINT (320, 240), 15, 15
PAINT fills the area with a color. Stops painting when it reaches the specified color on the
screen. Coordinates (320, 240) tells PAINT where to start painting, and the first "15" says
that as the fill color to use bright. The second "15" tells it to stop painting after reaching
anything that is bright white.
The compositions of the wheels
Concentric circles are very easy to draw:
SCREEN 12
CLS
FOR I = 5 TO 200 STEP 5
CIRCLE (320, 240), I, 15
NEXT I
Using CIRCLE, PAINT and some random numbers, we can do some interesting pictures:
SCREEN 12
CLS
FOR I = 1 TO 50
X = INT (RND * 640)
Y = INT (RND * 480)
R = INT (RND * 100)
Color1 = INT (RND * 16)
CIRCLE (X, Y), R, Color1
PAINT (X, Y), Color1, Color1
NEXT I

Chapter 22 - INKEY $
So far, using INPUT to get the keyboard. With INPUT is the problem that the program stops
until the user presses the Enter key. Would not it be nice to keep the program running and
still be able to get the keyboard? This allows you to do INKEY $. The use of INKEY $ is
very important if you want to make the game "in real time".
Fix the clock program, allowing the user to press any key to stop the program. In this way, he
does not need to know anything about the Break key.
CLS
LOCATE 3, 1
PRINT "Press anything - STOP"
TO
LOCATE 1, 1
PRINT TIME $
SLEEP 1
LOOP WHILE INKEY $ = ""
Not bad. Now you do not need to teach the user about the Break key. We can do the same in
any of our other program that requires the Break key. If you do not press a key, INKEY $
returns nothing, or the empty string "".
The next program will sit in a loop getting keys from the keyboard by INKEY $ and printing
them on the screen:
CLS
TO
Key $ = INKEY $
IF Key $ <> "" THEN
PRINT Key $;
END IF
LOOP
This small program can be used to find the various secret codes used by INKEY $ and let you
know when the arrow keys are pressed. It is very useful in game programming, where the
arrow keys might control a game. If you press the arrow key, you will see that a space and a
letter.

Chapter 22.5 - String Functions
Concatenation
Konka-the-what? It's just a fancy word for putting things together, one after the other. It is
much easier to do than to say. When you use the plus sign "+" with strings, it does not add
them. Instead, it puts them together.
A $ = "Hello"
B $ = "Here!"
C $ = A $ + B $
PRINT C $
It will print "Hello here."
LEFT $ () and RIGHT $ ()
LEFT $ () and RIGHT $ () allows you to work with parts chains. Try this example:
A $ = "Ted Felix"
B $ = LEFT $ (A $, 3)
PRINT B $
LEFT $ (A $, 3) means "take the A $ 3 characters from the left." Since the 3 characters from
the left is "Ted", the program prints "Ted", as expected. Try to change the number from 2 to 5
and see what happens.
Once you understand LEFT $ (), RIGHT $ () is easy. Try this:
A $ = "QBASIC is cool"
B $ = RIGHT $ (A $, 5)
PRINT B $
RIGHT $ (A $, 5) means "take the A $ 5 characters from the right. This gives us the" cool ".
MID $ ()
LEFT $ () gives us something on the left side of the chain. RIGHT $ () gives something to the
right of the chain. MID $ () gives us something from the center (middle) . Try this:
A $ = "one two three"
B $ = MID $ (A $, 5, 3)
PRINT B $
MID $ (A $, 5, 3) means "take 3 characters from the middle of A $, starting at the fifth
character. This gives us the middle word" two ".
You can also use the MID $ () to change parts of what is in the variable text. Try this:
A $ = "welder"
PRINT A $
MID $ (A $, 3, 2) = "in"
PRINT A $
Here we replace "and" the welder by "in". This gives us a completely different word.
This could be a pretty sneaky way to hide in the program such thing as a password. Someone
who does not know how to program in QBASIC, it could not figure out.
LCASE $ () and UCASE $ ()
When you need to convert the string into written in all capital or all lower case letters,
UCASE $ () and LCASE $ ().
A $ = "Ala has a cat muttering"
PRINT A $
PRINT UCASE $ (A $)
PRINT LCASE $ (A $)
You can use UCASE $ () and LCASE $ () for immunization tests against letters. In other
words, the size of the letters will not be taken into account. Here's an improvement to the
previous program:
CLS
INPUT "Enter your name:", Name $
IF LCASE $ (Name $) = "jane" THEN
PRINT "Go away!"
ELSE
PRINT "Hello"; Name $; . "How are you?"
END IF
In this new version, the user can type "mike", "Mike" or even "FRED", and the name will be
recognized.
STRING $ () and SPACE $ ()
Let's say that you need to write on the screen 20 stars in one line. You could do this:
PRINT "********************"
But there was a better way. How about a FOR loop?
FOR I = 1 to 20
PRINT "*";
NEXT I
PRINT
It works well, but QBASIC an even easier way to do this with STRING $ ().
PRINT STRING $ (20, "*")
The first argument to the STRING $ () is how many times you repeat the question. The
second argument is the character that is to be repeated. So STRING $ (20, "*") means "to
write me 20 stars."
If you want to insert a lot of space, you could do it with the help of
PRINT "A"; STRING $ (20, ""); "B"
Or you can use SPACE $ ().
PRINT "A"; SPACE $ (20); "B"
FOR loops always doing interesting things:
FOR I = 0 to 20
PRINT SPACE $ (I); "QBASIC!"
NEXT I
LEN ()
LEN () gives us the length of the string. Try this:
A $ = "Hello"
PRINT LEN (A $)
As expected, it should print the number 5, because the word "Hello" has 5 characters.
LEN () is useful in loops FOR, when you're not sure how long is a string, and does not want
you to count:
A $ = "Welcome to QBASIC!"
FOR I = 1 to LEN (A $)
PRINT LEFT $ (A $, I)
NEXT I
LEN () function is very useful when you want the user entered string. Try this:
INPUT "Enter a string:", A $
PRINT "Written string is"; LEN (A $); "Chars."
CHR $ () and ASC ()
Computers, in fact, know only numbers. To generate a sequence of letters, computers convert
letters to numbers, because they can work. CHR $ () and ASC () allow us to do the same
conversion.
CHR $ () converts a number to a character. We've seen it in the previous chapter. Try this:
FOR I = 14 to 255
PRINT I; CHR $ (I); "";
NEXT I
This program displays all the character numbers from 14 to 255, and the characters that they
represent. CHR $ () function is very useful for the preparation of characters that are not on
the keyboard. Like this:
PRINT STRING $ (40, CHR $ (1))
There are a couple of interesting characters between CHR $ (1) and CHR $ (31). For
example, CHR $ (7) does "beep". Try it:
PRINT CHR $ (7)
There are also other interesting things. Play around a bit with the CHR $ (), and you'll find a
few.
ASC () is the opposite of CHR $ (). ASC () takes a character and gives his number. Try it:
PRINT ASC ("A")
This program prints 65 because the character code of a large "A" is a 65 code, which
QBASIC uses to convert letters to numbers is called "ASCII" (pronounced "flat").
INSTR ()
INSTR () allows you to look for a string in another string. If it finds it, tell us where he is. Try
it:
A $ = "Hello everyone"
PRINT INSTR (A $, "all")
This program prints "10", because "everybody" was found in the tenth position in "Hello
everyone". If the string is not found, INSTR () returns zero.
INSTR () can be very useful when you want to split a string into parts:
A $ = "two pieces"
SpacePos = INSTR (A $, "")
PRINT LEFT $ (A $, SpacePos)
PRINT RIGHT $ (A $, LEN (A $) - SpacePos)

Chapter 23 - Comments and constant
Most programming languages allow you to add notes to your programs that are ignored by
the computer. This allows you to explain what is in the program, someone who can read the
program in the future. In QBASIC, at the beginning of the comment, we use the apostrophe
('). Here is an example:
'The draw boxes on the screen
'This is a comment, QBASIC will ignore it.
SCREEN 12
CLS
'Draw 50 times
FOR I = 1 TO 50
'Select the position rectangle
X1 = INT (RND * 640)
Y1 = INT (RND * 480)
X2 = INT (RND * 640)
Y2 = INT (RND * 480)
'Choose a color for the box
Color1 = INT (RND * 16)
'Draw the box
LINE (X1, Y1) - (X2, Y2), Color1, BF
NEXT I
The computer will ignore all those comment lines, but we humans can read them and
remember how the program works. Good programmers use comments to help others
understand what has been done. Comments can also help us to remember what we did when
we return to the program for some time.
Fixed
Another way to make the program easier to understand is to use constants. Solid look and act
like variables, but they can not change. Here's a handy program:
CONST Pi = 3.141593
INPUT "Enter the radius of a circle", Radius
PRINT "The circumference is:"; 2 * Pi * Radius
PRINT "The area is:"; Pi * Radius * Radius
If you do not use the constant Pi, we have the number 3.141593 in this program to copy two
times. Using a constant makes the program easier to read and understand. It also keeps us
from making mistakes while copying.

Chapter 24 - Sub-Procedures (SUBs)
When the program gets long, you have to divide it into smaller pieces that are easier to work
with. QBASIC calls these pieces "sub-procedures" or SUB. Other programming languages
use other names, such as a subroutine.
To work with SUBs in QBASIC, you need to look to the dialog "SUBs", which shows us a
list of our SUBs. Select "View | SUBs ..." from the menu to move to the "SUBs". You can
also press the F2 key to get the same thing faster. In the window you can select the SUB,
which we want to work, or you can select the main module (Main Module). If you are just
starting (File | New), you will see that the main module is called "Untitled" and has no SUBs.
In QBASIC, you can define a new SUB simply by typing it. This will bring you to view the
new procedure. Try typing this:
SUB DrawCircle
CIRCLE (320, 240), 100, 15
END SUB
Note that when you hit Enter after the first line, you've been moved to a new screen with your
new SUB is. Now if you go to the dialog "SUBs" (View | SUBs ...), you can see that you
have a SUB named "DrawCircle" and the main module named "Untitled".
Now you need to go back to the main module to actually use the new SUB. From the menu,
select View | SUBs ... to get SUBs dialog box. Now double-click the "Untitled" to return to
the Main Module. The screen will go blank, but do not worry, your sub is still there. Now
enter and run it:
SCREEN 12
CLS
DrawCircle
See? DrawCircle did what had to be done.
Try to add another sub. See if you can remember the steps. Return to the previous example, if
you need help.
SUB PlayMary
PLAY "e8 d8 c8 d8 e8 e8 e4"
END SUB
Now you need to change the main module to use our new SUB. So back to the Main Module
and change it to look like this:
SCREEN 12
CLS
DrawCircle
PlayMary
Now run it and you should see a circle and hear the song.
Dividing programs into smaller parts, as this will help you to understand large programs.
Arguments
Sometimes you want to pass to the procedure SUB number or string. QBASIC lets it. Here is
the new version of the procedure DrawCircle:
SUB RysujOkrag2 (Radius)
CIRCLE (320, 240), Radius, 15
END SUB
This version allows us to pass in the Radius. When we do this, Ray called a "parameter" and
"argument" to our SUB. This is how we pass an argument of the main module:
SCREEN 12
CLS
DrawCircle
RysujOkrag2 (20)
PlayMary
We could also in the main module to do something like this:
SCREEN 12
CLS
FOR I = 5 TO 200 STEP 5
RysujOkrag2 (I)
NEXT I
Changing arguments
When you need to say something to the main module, you can change one of the arguments
in the SUB and the main module will see the change.
AddOne SUB (X)
X = X + 1
END SUB

CLS
I = 0
AddOne (I)
PRINT AND
When you run this program, writes on the screen the value of 1 is because, since the value of
I is changed by the AddOne SUB. If you only need to return a value, sometimes the better
choice is a FUNCTION. It will be described later.
Range
What if we had a variable in the main module and the SUB and it so happened that they had
the same name? Will it be the same variable? Let's find out. Enter this SUB:
SUB Range
PRINT "Scope says:"; X
X = 23
END SUB
And the main module:
X = 15
Range
PRINT "Main Module says:"; X
I run it. What happened? Range said, "0", because to Scope, X was a new variable. Main
Module said 15, because Scope did not change Main Module's X, he changed his own X.
Scope and X from the Main module are different variables.
Variables that you create in a SUB can not be seen by the Master. Variables in the Main
Module can not be seen by the SUB. If you need to share variables, you can pass them as
arguments to the SUB.
Global Data
It is possible to do so, so that the variables in the Main Module available to SUBs without
passing them as arguments. Add "SHARED X" to the Scope in this way:
SUB Range
SHARED X
PRINT "Scope says:"; X
X = 23
END SUB
Now, when you run it, you will see that the SUB range can already see the Main module.
Scope no longer has its own X. This is called a "global data" (or "global variables") , as they
are everywhere visible, and if you can, you should avoid it. Most developers consider it to be
dangerous, because it is difficult to discern which SUB procedure can change the value of the
variable.
You can also make the Main Module global variable for all procedures SUB, by adding the
module, "DIM SHARED" before you set X to 15:
DIM SHARED X
X = 15
Range
PRINT "Main Module says:"; X
In this way it is easier to see which variables are global, because it can be found in the Main
Module. The problem may be that these variables are global to all SUBs in the program.
Typically, only some SUBs need to see global variables; In this case, it is better to use inside
SUB SHARED.
Object-oriented programming
When you start to worry about sharing variables between SUBs and the Main Module, then
you're probably ready to start learning object-oriented programming. This style of
programming makes it easier to share variables between SUBs and still produce code that is
easy to understand. Visual Basic, Java, and C # are programming languages that are object-
oriented programming features and are fairly easy to learn.
STATIC
Note that every time you call a SUB, its variables are lost when the SUB. Here is an example:
SUB Counter
C = C + 1
PRINT C
END SUB

CLS
Counter
Counter
Counter
Not a good counter, as always prints "1". We can use STATIC to tell QBASIC that we do not
want the disappearance of C after the SUB. Then get the behavior we expect. Change
Counter procedure as follows:
SUB Counter
STATIC C
C = C + 1
PRINT C
END SUB
And now much better.
Object-oriented programming languages offer many ways to avoid the use of STATIC
variables. When you find yourself making lots of STATIC variables, it is probably time to
learn object-oriented language.
Functions
Functions are just like SUBs, but they return a value. Here is an example:
Add FUNCTION (X, Y)
Add = X + Y
END FUNCTION
And this main module, with which she works:
PRINT Add (3, 4)
DECLARE
When entering the example programs in this chapter, you may have noticed that the QBASIC
editor adds to the programs "DECLARE" statements. Why is he doing? The "DECLARE" is
a warning to QBASIC that in this program are the SUB and FUNCTION procedures. Without
this warning, QBASIC not know what we mean when we call them. You'd think that was a
syntax error and the program would stop.
Fortunately, QBASIC takes care of this by inserting the letter DECLARE. Unfortunately, in
the long program, it might put DECLARE anywhere that looks ugly. Fortunately, you can
move the DECLARE where you want (so long as it is placed before the first use of the SUB
or FUNCTION), and QBASIC still takes care of the rest.

Chapter 25 - Data Structures
Built-in Types
QBASIC offers five built-in data types. Each of these types can be defined by a single
character after the variable name. You can also specify a type using a DIM. It is important
that when writing a program to indicate the correct types. The following descriptions of each
type will help you make the right decisions.
Variables single-precision (single-precision)
Keep the number of decimal part. The single-precision variable can receive up to seven
digits. The type-in this variable is "". If you do not specify otherwise, any variable without a
type is a single-precision variable. Here are some examples of creating and using these
variables:
X = 1.5
DIM y AS SINGLE
Y = 2.1
Z! = 2.5

PRINT X; Y; Z!
Note that the DIM statement can be used to tell QBASIC the type of the variable. Then for
such a variable does not need to use a (suffix) type.
String variables (String)
Type handles strings of characters. For string variables can not do math. In a DIM statement,
use "STRING" to create a string variable. The type of the variable is "$" Here are some
examples of creating and using string variables:
X $ = "Hello"
DIM y AS STRING
Y = "Goodbye"

PRINT X $
PRINT Y
Variables Integer (Integer)
Integer type supports a number without decimal places. These numbers range from -32768 to
32767. Calculations may be faster than a single-precision floating point. For programs that
need to run very fast, using integers can be uuteczne. In a DIM statement to create them, use
"INTEGER". The type is for them, "%". Here are some examples of creating and using
variables of type Integer:
X% = 32
DIM y AS INTEGER
Y = 55

PRINT X%; Y
As Integer calculations are very fast, generally meet the following line at the beginning of
programs in QBASIC:
DEFINT AZ
It tells QBASIC to stop assuming that all variables are single precision, and instead to assume
that they are all integer. In this way, you do not need to use DIM or "%" symbol, in the whole
program, all variables are of type Integer.
Long integers (Long-Integer)
This type handles numbers without decimals. Long-integers may range from -2147483648 to
2147483647. Calculations on them are usually almost as fast as Integer. This can be useful
for programs that need to work very quickly. In a DIM statement to create them, use
"LONG". The type of integer variable is "&". Here are some examples of creating and using
integer variables:
X & = 65536
DIM Y AS LONG
Y = 121072

PRINT X &; Y
Variables double-precision (Double-Precision)
This type supports the number of decimal places. The double-precision variable can receive
up to fifteen digits. They are used where the need for highly accurate calculations. In a DIM
statement to create them, use "DOUBLE". The type is "#". Here are some examples of
creating and using double precision variables:
X # = 3.14159265358979
DIM y AS DOUBLE
Y = 1.23456789012345

PRINT X #; Y
Boards
Blackboard allows you to store a list of things. Arrays are very similar to variables, but may
contain more than one thing. Try this:
N $ (0) = "Tzadok"
N $ (1) = "John"
N $ (2) = "Ania"
N $ (3) = "Fred"

FOR I = 0 TO 3
PRINT N $ (I)
NEXT I
The number inside the parenthesis "(1)" is called "index".
Arrays can also store the number.
FOR I = 0 TO 10
A (I) = I * 2
NEXT I

FOR I = 0 TO 10
PRINT A (I)
NEXT I
Arrays are limited to holding only 11 items (0 to 10). If you go over 10, you get an error
"Subscript out of range" ("Index out of range") . To create larger arrays, you can use DIM to
tell QBASIC how big the array will be:
DIM A (20)

FOR I = 0 TO 20
A (I) = I * 2
NEXT I

FOR I = 0 TO 20
PRINT A (I)
NEXT I
Arrays are perfect for programs that need to keep a list of things. Could use arrays to create a
program phone book or program that keeps people in your class.
TYPE
Sometimes you will want to keep together a group of variables, because together they
describe something. TYPE command allows you to create your own collection of variables.
Here is an example:
TYPE FriendType
Name AS STRING * 20
PhoneNumber AS STRING * 14
END TYPE

Colleague DIM AS FriendType

Friend.FullName = "Joe Blow"
Friend.PhoneNumber = "1-310-555-1212"

PRINT Friend.FullName; ":"; Friend.PhoneNumber
TYPE makes our new type, which is a collection of variables. DIM creates a new variable of
that type. When we work with the types, use the variable name, followed by a period ("."),
And the name of the variable of TYPE.
Since TYPE lets you use a single variable to represent a collection of variables, you can use
TYPE to pass multiple parameters to a SUB one fell swoop. This can be a good way to avoid
using too many SHARED in the SUB.
In QBASIC TYPE may include any of the built-in types. Type can also include another
TYPE. However TYPE may not contain the array. Visual Basic allows it, but not QBASIC.
Database
The use of time tables and TYPE allows you to create what is known as a database. Try this:
TYPE FriendType
Name AS STRING * 20
PhoneNumber AS STRING * 14
END TYPE

'Database
DIM Friends (2) AS FriendType

'Fill the database with names and numbers
Colleagues (0). Name = "Joe Blow"
Colleagues (0). PhoneNumber = "1-310-555-1212"

Colleagues (1). Name = "John Cloud"
Colleagues (1). PhoneNumber = "1-340-555-6545"

Colleagues (2). Name = "Charles Rain"
Colleagues (2). PhoneNumber = "1-350-555-2421"

'Print out the entire database
FOR I = 0 TO 2
PRINT Friends (I). Name; ":"; Friends (I). PhoneNumber
NEXT I

Chapter 25.5 - Type Conversion
STR $ () and VAL ()
So far, we have used string variables to hold the chains a number of variables to store
numbers. And what if you really need to do calculations on numbers that are in a string
variable? Or maybe you need to somehow get some numbers into a string variable? QBASIC
provides us with features of the STR $ () and VAL ().
STR $ () will convert the number to a string. Like this:
A = 25 'A can store only numbers
PRINT A
B $ = STR $ (A) 'Convert a string, store in B $
PRINT B $
VAL () will convert from a string to a number. Like this:
A $ = "25" 'You can not do any math with a string variable
PRINT A $
B = VAL (A $) 'Convert A $ to a number stored in B
PRINT B
Converting Numbers
Includes CINT (), FIX (), INT (), CDbl (), CSng (), CLng ()

Chapter 25.75 - PRINT USING
(Author leave this section blank.)
If the usual commands PRINT will print the number one under the other, QBasic align
them to the left, we do it differently, eg when you add in the paper. To QBasic wrote us a
number in such a way, you use the PRINT USING:
PRINT USING "# # # # #. # #"; 1234.567
PRINT USING "# # # # #. # #"; 789
Fragment "# # # # #. # #" Is the format string. Characters # define in the position of the
digits of a number. If the number has a fractional part longer than the number of places
provided for her in the chain, it is rounded. For integers, the fractional part contains zero
(which normally QBasic leaves).
PRINT USING uses other than # formatting characters. For a list of all of them can be
found in the Help for Qbasic "

Chapter 25.9 - DATA and READ
Loading an array with a lot of data can be very boring.
'Load up the array
A (0) = 10
A (1) = 24
A (2) = 31
A (3) = 15
A (4) = 67
A (5) = 34
A (6) = 87
A (7) = 92
A (8) = 14
'... It can pull some time in August ...

FOR I = 0 TO 8
PRINT A (I)
NEXT I
To save space and typing, QBASIC provides the DATA and READ. You can place a list of
data values in the DATA command and load it into an array using READ. The following
program is doing exactly what the previous one.
DATA 10, 24, 31, 15, 67, 34, 87, 92, 14

FOR I = 0 TO 8
READ A (I)
NEXT I

FOR I = 0 TO 8
PRINT A (I)
NEXT I
QBASIC reading the code, leaving the DATA command. Draws attention to them only when
it finds the READ command. Each time a READ happens, QBASIC gets the value of the
DATA command and places it in a variable in the READ statement.
RESTORE
RESTORE tells QBASIC which DATA command to start reading. In your program you may
need to load several different arrays. RESTORE allows you to organize the DATA command
in every way, how you want.
Names:
DATE Fred, John, Jacek, Zosia
Values:
DATA 10, 24, 31, 15, 67, 34, 87, 92, 14

'Start with the DATA statement after "Values"
RESTORE Values
FOR I = 0 TO 8
READ A (I)
NEXT I

'Start with the DATA statement after "Names"
RESTORE Names
FOR I = 0 TO 8
READ N $ (I)
NEXT I
RESTORE tells QBASIC to start reading from the next DATA statement after the label. The
label is the name as "Names" or "Values". Note that when you create a new label, we use a
colon ":", but when we use the label command RESTORE leave the colon.
Charging database
DATA command are excellent databases. Here is the new version of the example database,
this time uses DATA.
DATA "Joe Blow", "1-310-555-1212"
DATA "Jacek cloud", "1-340-555-6545"
DATA "Charles Rain", "1-350-555-2421"

TYPE FriendType
Name AS STRING * 20
PhoneNumber AS STRING * 14
END TYPE

'Database
DIM Friends (2) AS FriendType

'Load the database from the DATA statements
FOR I = 0 TO 2
READ Friends (I). Name and colleagues (I). PhoneNumber
NEXT I

'Print the entire database
FOR I = 0 TO 2
PRINT Friends (I). Name; ":"; Friends (I). PhoneNumber
NEXT I

Chapter 26 - Reading and Writing Files
So far, our programs were dependent on the programmer, to give them data to work. This
would not work well in the case of the phone book. The user must fill in the names and phone
numbers. QBASIC allows you to get information from the user by INPUT. But when the
program ends, this information is lost.
Save the file
The solution to this problem is to allow the user to enter information, and then the program
will store it in a file on your hard disk. QBASIC offers a number of ways to do this. Try this:
INPUT "Enter your name:", Name $
OPEN "testfile.txt" FOR OUTPUT AS # 1
WRITE # 1, Name $
CLOSE # 1
When you run this program and type in your name, he will put them in a file on your hard
drive called "testfile.txt". You can use Notepad to find it and make sure your name is there.
You need to figure out where QBASIC put the file. It will be a little complicated. If you exit
QBASIC and from the DOS prompt enter this:
type testfile.txt
you should see your name and whatever you typed. DOS command "type" copies the
contents of a file on the screen. You could also try this:
notepad testfile.txt
This should cause Notepad to your file. When you work with files is a good idea to know
how to put them into Notepad. This way you can look at them to see if they contain what you
expect.
OPEN, WRITE, and CLOSE
There are three commands: OPEN, WRITE, and CLOSE that are needed to save the
information to a file. The command OPEN (Open) tells QBASIC three things:
1. file name (testfile.txt);
2. if you want to save the file (OUTPUT), or read from a file (INPUT);
3. file number (# 1 in this example).
Once the file is open, we will use the file number to let QBASIC know which file you want to
save. You could have many files open at the same time, so the file number lets QBASIC
know which file you want to work.
WRITE command (Write) tells QBASIC which file you want to save (# 1), and what we want
to save ($ name). This is very similar to the PRINT command, but instead of sending the
information to the screen WRITE sends them to a file.
At the end you have to close (CLOSE) file to QBASIC know, we're done. Otherwise,
QBASIC might not write anything to the file. CLOSE command only needs to know which
file you want to close, so it requires only the file number.
Reading from a file
The following program retrieves the name and print it on the screen:
OPEN "testfile.txt" FOR INPUT AS # 1
INPUT # 1, Name $
CLOSE # 1
PRINT Name $
There are three main things different in this program, if you compare it with the previous one.
1. OPEN command uses "INPUT" instead of "OUTPUT". This tells QBASIC that we
are going to retrieve the data from the file.
2. The INPUT statement that we have seen before, is used to read from the file. # 1 tells
him that we want to read from file # 1 When using INPUT in other programs, there
was no # 1 No file number INPUT retrieves data from the keyboard. With the number
of file - gets the data from the file.
3. Instead of downloading anything from the user at the beginning of the program, we
show at the end of what has been read from a file, the good old command PRINT.
One thing that has not changed at all is the CLOSE. Close the file # 1 to QBASIC know that
we're done with it. Although he probably will not lose any data if you do not close the file in
this case, it is still a good thing to do. QBASIC can open so many files, so if you leave one
open, we can not open any more.
Keeping a log
Sometimes it can be very useful to write to a file, when the program was launched, to be able
to see what happened next. It is called "logging". We can use the "APPEND" (Include) in the
OPEN statement to open the file and just adding to the end.
OPEN "logfile.txt" FOR APPEND AS # 1
PRINT # 1, "The Home"; TIME $
CLOSE # 1

CLS
INPUT "Enter your name"; Name $
PRINT "Hello"; Name $

OPEN "logfile.txt" FOR APPEND AS # 1
PRINT # 1, "Program Stop"; TIME $
CLOSE # 1
In this program, logged two things, the start time of the program and the time of its
completion. Run the program several times, then exit QBASIC and type:
notepad logfile.txt
This will show you what is in your log.
Reading from files
Ideas: Fortune Teller using a text file as input. This could be a combination of tables with
reading from a file.
Keeping Track
Let's say that we want our program to remember who it is registered to. We also want to
count the number of times it runs. We could try something like this:
CLS
INPUT "Enter your name to register in the program:", Name $
PRINT "Thank you,"; Name $
Count = Count + 1
PRINT "The program is registered to:"; Name $
PRINT "This program has been run"; Count; "Times."
PRINT "We hope you have enjoyed it."
But it does not work. Why? Because QBASIC can not remember the values of variables
Name $ and Count from one run to the next.
To fix this, we need to use a file. We can read the file before the program starts, and write the
file back out when the program is finished. In this file, write the user's name and how many
times the program was running.
The code that does this, is a bit more complex than the ones we did before. This is because
QBASIC handles file errors in a strange way. Our program has to handle one file error. When
will be run for the first time, there will be no registration file, which he has read. So OPEN
fails. We have to handle, otherwise our program will not work.
'If there are any problems, QBASIC will jump to ErrorHandler below.
ON ERROR GOTO ErrorHandler

'This is the error code who is saved
'By support for error (error handler).
DIM ErrorCode AS INTEGER

CLS

'Always reset it before you do something that you want to check.
ErrorCode = 0
'Try to get the name and count from the file.
OPEN "register.txt" FOR INPUT AS # 1

'If there is no file
IF ErrorCode = 53 THEN
'Get the name from the user
INPUT "Enter your name to register in the program:", Name $
PRINT "Thank you,"; Name $
'And set the counter to 0
Count = 0
ELSE
'Get the name and count from the file.
INPUT # 1, Name $, Count
CLOSE # 1
END IF

Count = Count + 1
PRINT "The program is registered to:"; Name $
PRINT "This program has been run"; Count; "Times."
PRINT "We hope you have enjoyed it."

'Save the name and count for the next run.
OPEN "register.txt" FOR OUTPUT AS # 1
WRITE # 1, Name $, Count
CLOSE # 1

'This END prevents us from running the error handler
'At the end of the program. Stops the program,
'Just like pressing the Break key.
END

'QBASIC will jump here, if you happen to get an error.
ErrorHandler:
'We need to move the error code to a variable, otherwise it is not
'See it because ERR is reset when the handler
'Will end.
ErrorCode = ERR
RESUME NEXT
Error handling for file
"ON ERROR GOTO ErrorHandler" tells QBASIC that when there is a problem, the program
should immediately jump to "ErrorHandler: '- subroutine handle errors, which you'll see at
the end of the program. Here we can get the error code that is located in a QBASIC variable
called "ERR" and copy it to our own variable "ErrorCode". If we do not, we will lose the
error code stored in the ERR. RESUME NEXT tells QBASIC to continue the program from
where the error occurred.
I'm trying very hard to avoid using GOTO in my programs. Programs that use GOTO can be
very difficult to understand. Unfortunately, in this case, QBASIC leaves us with no
alternative. We need to use GOTO. So I tried to use the simplest solution that keeps the code
easy to trace. With this small error handler, we can simply assume that ErrorCode will
contain the error number, if something goes wrong. You can not just forget to reset it,
otherwise you'll watch old mistakes!
Random I / O
Up to this point been using something called the "Sequential I / O". Sequential means "one by
one". I / O stands for Input / Output - Input / Output. When we write to the file name of the
user and the timer starts, write them one after the other. This is a record of the sequence.
When we read the name and count, we read them one after the other. First name, then
counter. This is a sequential read. All together gives us a "sequential input and output" or
"sequential I / O".
Random I / O allows you to read and write data to any part of the file, in the order they want.
This is very useful when you have very large files and do not have enough time or memory to
read everything in the file sequentially (one after another). Random I / O (random I / O)
allows you to jump right to the data in the file and read or write it.
Even in very large and complex programs free I / O is rarely used because of its complexity.
Imagine that the program has a bug and writes the wrong place in the file! The file could be
destroyed. We will not discuss the free I / O. But, if you need him, he is in QBASIC.

Chapter 27 - Sample programs
Read the Manual
You have learned a lot. If you've gotten to this place, and are still having fun, it's time to do
some of your own programs. assistance to QBASIC is what you should read if you are
curious about what else QBASIC can do. He can do a lot more than I showed you in this
book.
Some of the following examples can do things that have not seen mentioned in the book. See
if you can figure out what these new things, looking for help, which is attached to QBASIC.
(Aid to qbasic - QBASIC Help, available in the interpreter QB - is, of course, in English. But
its translation into Polish can be found here . Prov. crowd.)
Guesser Numbers
In this game, the computer generates a number between 1 and 10 Try to guess the number.
CLS
RANDOMIZE TIMER
PRINT "Welcome to Zgadywaczu Numbers."
PRINT "I think the number between 1 and 10"
Number = INT (RND * 10 + 1)
TO
INPUT "What have guessed?", You agree
IF Guess = Number THEN
PRINT "All right!"
EXIT TO
ELSE
PRINT "Try again."
END IF
LOOP
Additional things
Alarm clock
More examples
I have a few more examples on my site "SupaSoft". Just look for "QBASIC". Here are a few
that you can find there:
Note: If you manually enter the addresses of the parties, make sure you get capital letters
exactly as shown. For example, make sure you typed "SupaSoft" and not "SupaSoft". If your
browser you get the message "can not be displayed", probably this is the reason.
http://www.tedfelix.com/SupaSoft/snowflak.html - Snowflake Generator snowflakes. How
real snowflakes, no two are the same.
http://www.tedfelix.com/SupaSoft/strsplt2.html - Star Split 2: Simulation of a starry sky.
http://www.tedfelix.com/SupaSoft/willtell.html - William Tell: Pretend William Tell and try
to shoot the arrow head of a hostage.
http://www.tedfelix.com/SupaSoft/capture.html - Capture: Try to trap two robots in a maze of
blocks.
http://www.tedfelix.com/SupaSoft - My freeware site. Seek "QBASIC" in the descriptions of
programs to find the sample QBASIC.

Appendix A - Finding and installing
QBASIC
If you see the message "Bad command or file name", then you need to get QBASIC on your
machine.


Unfortunately, this is not the easiest thing in the world. You can ask someone to walk through
this with you.
On the Internet
There are several places on the Internet where you can get a copy of qbasic. Usually, the file
is called "qbasic.zip". Here are a few sites that I found:
http://www.svatopluk.com/qbtutor/tut1.htm - QBASIC tutorial at King Svatopluk's
Court
Probably a lot of other places to find. Using a search engine such as www.google.com and
search "qbasic.zip" usually gives good results. If you find a QBasic in this way, be sure to get
"the interpreter version 1.1". This is a version of qbasic I used to write this book. It is the
easiest to use and least complicated. When you are using version 1.1, you can try and find
ver. 4.5, which has a number of nice properties.
The Polish Internet is the easiest way to get QBasic from the AGH
http://adam.imir.agh.edu.pl/dydakt/basic/index.htm . There is also a brief description
language and a set of exercises for students. (Prov. crowd.)
When you have qbasic.zip, you need to unpack it and move qbasic.exe and qbasic.hlp to c: \
windows \ command. Anyone who is familiar with the files "zip", will help you do it.
Windows 95
QBASIC is a CD-ROM Insert the Windows 95 CD with the Windows 95 CD-ROM drive.
Should pop up a window that close (click on the "X" in the upper right corner of the
window).
DOS or Windows?
There are two ways to copy files QBASIC to your computer. Using MS-DOS mode is the
fastest method, but you need to know the drive letter of the CD (for example, "d", "e" or
"from"). The method described in the "Windows Explorer" is a bit slower, but you do not
need to know the letter of the CD.
MS-DOS
You should already be in MS-DOS mode, trying to start QBASIC. It makes things easier.
Accept that your CD-ROM drive has the letter "d". If not, enter the correct letter in the
command "copy" below. (<Enter> Means "Press <Enter>"):
c: <Enter>
cd \ windows \ command <Enter>
copy d: \ other \ oldmsdos \ qbasic. * <Enter>
From the translator: QBASIC is also on the installation CD of Windows 98, but in a
different folder. If the disc you are using Windows 98, the "copy" command, type:
copy d: \ tools \ oldmsdos \ qbasic. * <Enter>
This should copy qbasic.exe and qbasic.hlp to your computer. Go to the "Finished!" to see if
everything went well.
Windows Explorer
If you do not want to try the method of mode MS-DOS, Windows Explorer can also be used
to get QBASIC. We need a Windows Explorer (not Internet Explorer) to copy files QBASIC
CD to the c: \ windows \ command. Click "Start," then "Programs", then "Windows
Explorer". On the left side you will see a list of drives on your computer. Look at the CD (it
has a little picture of a CD and it should say "Windows 95"). Click on this icon. In the right
column you will see a list of folders on the CD.
Finding QBASIC. Double click on the "Other", then double-Oldmsdos. Now you'll see a list
of files. Go through the list until you find two files named Qbasic. One is the same QBASIC,
and the second is the help file.
Selecting files QBASIC want to copy these two files to the c: \ windows \ command. Click
on the first file qbasic to turn it blue. This means that it is selected. We also need a second
Qbasic file. Press and hold <Ctrl> when you click on the second file. They should both be
blue. This means that both are selected (checked).
Copy to Clipboard <Ctrl> Press and hold it down, and now press C. This will copy the files
to the clipboard.
C: \ Windows \ Command Now click on the "Tools" menu in Windows Explorer, and then
click the "Go to ...". Type:
c: \ windows \ command
and press <Enter>.
Inserting from the Clipboard Now press <Ctrl> and holding it down, press V. This will
paste the QBasic files from the clipboard to the c: \ windows \ command.
Differences Windows 98 SE and Windows XP
(From interpreter) In Windows 98 SE and Windows XP tab "Tools" Windows Explorer is not
an option "Go to ...". So you would need to move to the directory c:, open the WINDOWS
folder, find and open the folder and only there COMMAND insert files by pressing Ctrl-V.
But often the WINDOWS folder is protected from intruders.
What remains? Old, honest diskette. Moreover, it can be used independently from your
system. In the "File" menu in Windows Explorer, click "Send To" and then click "3.5" floppy
disk. Qbasic files will be copied to a floppy disk. After this operation on the floppy disk will
still 1 132 032 bytes free - enough for your programs. QBASIC can be started up by opening
"My Computer", click on "3.5" floppy disk and then qbasic.exe.
Just like a floppy disk, you can put QBasic in any folder on your hard drive. You can then
make a shortcut on the desktop. To do this, click the RIGHT mouse button on the qbasic.exe,
select "Send To" and "Desktop (create shortcut)". The shortcut will be placed on the desktop.
Finished!
Phew! That would be enough.
You can close Windows Explorer (if you used it), go to the window the DOS prompt ( C: \
WINDOWS> _ C: \ WINDOWS> _ or C: \ WINDOWS \ COMMAND> _ C: \ WINDOWS \
COMMAND> _ ), Enter:
qbasic
and press <Enter>.

Books about QBASIC
In the original, the author presents a series of books on QBasic, written in English. With
things translated into Polish I know only one:
QBasic on a collision course! Greg Perry, Intersoftland, Warsaw 1993
comprehensive (275 pages) book with numerous examples of
commands taught to use most of the QBASIC. It does not include
procedures SUB and FUNCTION, so the programming style is closer
to the GW-BASIC.




Other Websites
Google's list of QBASIC tutorials
http://www.network54.com/Forum/13959
QBASIC Forum - talk to other folks who use QBASIC.
http://www.ethanwiner.com/
Ethan Winer's site - His book "BASIC Techniques and Utilities" is available for
download here.
http://piptol.qbasicnews.com/webring/goring.php?action=all - The QBASIC web ring
- lots of other interesting QBASIC sites.
http://www.libertybasic.com - Another flavor of BASIC for Windows. I do not
recommend LibertyBASIC, because its graphics support is difficult to use. It is very
important That a programming language have an easy way for kids to play with
graphics.
http://www.qwerty.com/basic.htm
http://www.conklinsystems.com/retro/trsman.shtml - Takes me back. I managed to
land a paper copy of the old TRS-80 manual, and you can download a PDF if you are
interested. See above.
From the translator: In the Polish Internet is also a few pages on QBASIC, often "stuck"
to the subject of Visual Basic; try the search engine Google . Almost all the Polish courses
Qbasic are stored on
http://members.lycos.co.uk/kursyprogramowania/kursy.php?id=k_basic&____ord____=1
169559776

Copyright 2007, Ted Felix, All Rights Reserved
May be copied or translated freely for non-commercial use.


Glossary
[In square brackets - the approximate pronunciation]
A
append [apend] - join
C
case [Kejs] - the case of circle [serkl] - circle
close [klouz] - close color [color] - Color



D
date [deity] - data debug [dibag] - (inform.)
debug declare [diklejr] - declare DOS - Disk
Operating System. Disk Operating System; in
M
middle [midl] - agent
N
name [Neiman] - name, surname, name of
the new [nju] - new next [Nekst] - next


About
open [oupn] - open the option [opszn] -
option selection or - or output [autput] -
(elec., inform.) output, the output

older computers band management programs
files on disk, in the current simulated
machines for compatibility with old software.
to [duu] - do draw [Drou] - draw





E
edit - edit, edit else [els] - otherwise,
otherwise the end - the end of the error
[eror] - error escape [iskejp] - escape exit
[eksit] - Output





F
file [Fajl] - file for - for

G
it is [gou here] - go to
H
help - help
I
if - if
... then ... if - if ... it ... input - (elec., inform.)
input, the input data

L
left - left, left line [lajn] - line locate [loukeit]
- place the loop [Luup] - loop




P
paint [pejnt] - paint play [PLEJ] - play print
- print


R
read [Riida] - Read restore [ristoor] - restore
the right [CME] - right, right run [ran] - Run



S
save [Seiwa] - to rescue, preserve, here: save
to disk screen [skriin] - screen search [sercz]
- search select [silekt] - select sleep [sliip] -
sleep sound [saund] - sound space [Speis] -
space here: space static [statik] - static,
motionless step - step string - string, here:
string









T
time [tajm] - time
V
view [WJU] - view
In
while [uail] - while write [CME] - write

http://deger.republika.pl

Potrebbero piacerti anche