Before starting our first program, we will declare the number of screen lines and rows that we will need in our program.
Qbasic allows us to use 13 screen modes, the first is text mode (0), we declare it by using SCREEN instruction ,followed by text mode number (zero), then we will display a message on the screen with PRINT instruction, the message must be between 2 quotes (").
Now lets build our first program that will display a "Hello everybody":
To run it, press F5 on the keyboard.
After running you will see on the screen :
Hello everybody
Press any key to continue
Then press any key, to return to the program. Run it again, you will see :
Hello every body
Hello every body
Press any key to continue
Tow messages was displayed, and we just programmed to show only one, so where is the second comes from?
Answer:
The first comes from our first running of the program, it displayed it And it returned to the next line, and after the second running the second Message was displaying in the second line.
So we see that the QB, displays messages and returns to a new line.
A question : how we display one message after each running of the program?
Answer :
We must clear screen, with CLS command.
Lets tray it:
To test it, run it twice or more, at any time you run the program you we will see one message displayed.
We also can display many messages in the screen, for example:
PRINT "mess 1"
PRINT "mess 2"
.
.
.
PRINT "mess n"
As you see if you run it :
The first message was displaying at the 1st line and 1st row.
The second message was displaying at the 2nd line and 1st row.
The third message was displaying at the 3rd line and 1st row.
And so on…
A question:
If we want to display a message at the (l) line and (r) row, what can we do?
Answer:
It's simple, we must use the LOCATE instruction, followed by the line number and row number.
And you knew that we declared the SCREEN 0, That's for dividing screen onto 80 rows and 25 lines, so the middle of the screen is 24/2=12;80/2=40.
Run this program to see:
I think its clear.
But all displayed messages are in white color, can we use another color?
Yes of course we can, in text mode we have 16 colors (0 :black to 15:white), to use them, we must use COLOR instruction followed by color number.
Look at this program:
Tray this one too.
30=14+16
add 16 to the color to have the some effect.
If we don't want to use locate, we can use TAB and SPC instructions.
Run this program to see:
The TAB instruction count the rows from the first row.
The spc instruction count the rows from the last row.
NB : use the semicolon between those instructions.
| color | code | color | code |
| Black | 0 | blue | 1 |
| green | 2 | Cyan | 3 |
| Red | 4 | Magenta | 5 |
| Brun | 6 | White | 7 |
| Gris | 8 | light Blue | 9 |
| light green | 10 | light Cyan | 11 |
| light Red | 12 | light Magenta | 13 |
| Yellow | 14 | light White | 15 |
Now we will pass to the difference between a number and a string (message ). Look at this program to see the difference:
When we use the quotation marks, that's mean that we will print a string, so will see at the screen :
4+2
When we don't use it, we will see the somme (4+2=) 6