QBasic Tutorials: Starting QBasic Part 4 - 7

Part 4 - The "PRINT" Statement

We will start this tutorial with the print statement, this is the easiest function to learn in qbasic. A good place to start your qbasic careers!! It is used like this:

PRINT "Hello!!"

Type this in on the main blue screen and then press F5 to see the first program you have done in qbasic!! This code should give you a blank black screen with the words, which you put in the speech marks, so this program, should just say :

Hello!!

On a blank black screen!! Now obviously to change what you want printed on the screen you just change what was in the speech marks :

PRINT "WHATEVER YOU WANT PRINTED ON THE SCREEN"

However you should realise that after running the second program the first program is still left on the screen. For example, after you ran program 1 and then you made your own writing up then you got something like this :

Hello!!
WHATEVER YOU WANT PRINTED ON THE SCREEN

In other words whatever you did previously is still on the screen. To overcome this problem you will need to learn a simple function, which takes us to our next chapter!!

Part 5 - The Clear Screen Function

After learning in Part 4 that you need to clear the screen you will be wondering what the code you need is, well don't worry it is still very easy!! Take a look:

CLS
PRINT "Hello!!"

This is the Clear Screen Function, it is simply "cls" This will clear the screen back to blank everytime you run a program. So you don't have your last program still on the screen. Easy isn't it!! You will need to put it on the first line of your program, so that it will clear the screen before doing the next operation!!!

Part 6 - Screens

QBasic has different screen modes depending on what you want to do!! Each screen mode has a different resolution for your text, and pictures!!

Screen 0 is the default screen. So if you don't assign a screen then qbasic will use this one!! Screen 1 gives you really big text Screen 2 gives you a slightly bigger than screen 0 with an italic type of text etc There are 13 screens for you to try out!! How to use the screen statement:

CLS
SCREEN 9
PRINT "hi"

By using this code you will see the difference which the screens make, to change the screen mode just change the number after the screen function. Just remember that you can use 0-13.

Part 7 - Color

So far what we have done has all been in plain black and white so why don't we spice it up a bit!! By using the color statement!! The color statement is just as easy as the other functions, and can be used for you to use different colors on your programs!! - color 0 - gives you black writing ( * note the screen will be blank because the writing and background colors are the same!!) - color 1 - gives you blue writing - color 2 - gives you a pretty green color etc There are up to 17 normal colors (0 - 16)!! From color 17 - 30 you can get flashing colored text!! However some screens do not support flashing text eg screen 9 To write in a red color the code is :

Screen 0 has been chosen as it is a normal screen which supports flashing text!!

CLS
SCREEN 0
COLOR 12
PRINT "hi"

This shows hi in a red font!!
To write in a flashing red font :

CLS
SCREEN 0
COLOR 28
PRINT "hi"

As you can see this shows "hi" in a red flashing text!!