Author: Maxim Kakitsev
Created on 26.03.01
Source URL: http://www.oocities.org/maxspaceuk
Qbasic Tutorial
Chapter I
When you open QBasic, you see a blue screen where you can type your program. Let’s begin with the basic commands that are important in any program.
Command PRINT displays text or numbers on the screen.
The program line looks like this:
PRINT “My name is Nick.”
Type the bolded text into QBasic and press F5 to run the program. On the screen you’ll see
My name is Nick.
Note: you must put the text in quotes, like this – “text”. The text in quotes is called a string.
If you put the PRINT alone, without any text, it will just put an empty line.
PRINT can also put numbers on the screen.
PRINT 57 will show the number 57. This command is useful for displaying the result of mathematical calculations. But for calculations, as well as for other things in the program, you need to use variables.
When you think, you keep words or numbers in your mind. This allows you to speak and to make calculations. Qbasic also needs to keep words or numbers in its memory. To do this, you use variables, pieces of Qbasic memory, which can keep information. A variable can be named with any letter, for example – a. It can also have a longer name, which can be almost any word. It is important to know that there are two main types of variables – that keep a number and that keep a word or a string of words.
In other words, you assigned the value 15 to the variable a.
Qbasic will now know that the variable named a keeps the number 15. Now, if you type
and run the program, the computer will show this number on the screen.
Example:
a$ = “It is nice to see you”
On the screen you’ll see:
The PRINT command can print more that one string on the line. To do this, put the ; sign between the variables. For example, you have two variables – name$, which contains name Rob, and age, which contains the number 34. Then, to print both name and age, you type:
PRINT “Name - ”; name$; “. Age - ”; age
What you see on the screen when you run the program will look like this:
Name – Rob. Age – 34
Or, you can type the program like that:
The result is:
Name – Rob
Age - 34
INPUT is a command that allows you or anybody else who runs the program to enter the information (text or number) when the program is already running. This command waits for the user to enter the information and then assigns this information to a variable. Since there are two types of variables, the INPUT command may look like this – INPUT a (for a number), or INPUT a$ (for a string).
Example (Type this program into Qbasic and run it by pressing F5)
You can use GOTO to jump not only back but also forward, to any line you want. Always remember to label that line. You can have more than one label, but in that case they should be different.
To the next chapter = >