TechnoZeal
Home
Qbasic


Tutorials
Basics


Links
Future         Software
Qbasic.com


Contact
E-mail me
Q u i c k B a s i c T u t o r i a l s

The Basics
-Added 12/26/00-

PRINT statement - Displays text on the screen
Syntax is as follows:

PRINT "text goes here"

There's not too much more to tell about the PRINT statement, so 
here's an example

PRINT "TechnoZeal rocks"

Output should look like this on the screen after the program is run:

=====begin output=====
TechnoZeal rocks
=====end output=======

There are a few things to note about the PRINT statement that I'm sure you will find later.  The 
first is if that if the text inside the quotes is greater than however many characters can it on 
one line of the output screen, the rest of the characters are carried over to the next line down.
Also the quotes are automatically ended in the programming prompt if you forget to close them.  
Another interesting thing to note is that if you close quotes, put a comma, and put another text 
string inside of quotations, the next string will be moved over about 15 spaces from the previous,
 an example of this would be the following program:

PRINT "Techno", "Zeal", "rocks"

Output should look something like:

=====begin output=====
Techno                 Zeal                 rocks
=====end output=======

There are five "print zones" on a screen.  Its basically just an invisible 5 columns with equal
widths on each line.  Every time a comma is put into place the text string will start in the next
print zone over.  If more commas than 4 are put in (signifying print zones 6 and 7 and so on....)
then the text just goes back to the line below and works with those print zones.  This really
shouldn't take too long to learn

One last thing you should be aware of is if you use more than 23 PRINT statements on one screen,
the lines at the top will get bumped off screen to make way for the new text encased in the newer
PRINT statements.  To get around this problem, refer below to the CLS, LOCATE, or even if you
wish to read that far, the WIDTH statements.


-Added 12/27/00-

LOCATE statement-moves the invisible 'cursor' for specified text to a certain row and column on 
the current screen.

Syntax is as follows:  

LOCATE row, col

An example would be the following:

LOCATE 12, 25 

There are a few things to note also with the LOCATE statement.  LOCATEs cannot be outside the 
current screen or an error will result.  Say the current text resolution is 80x25 (meaning 80 
columns and 25 rows), if a LOCATE 26, 100 is entered, an error will result.  The computer screen's
text coordinates are arranged like quadrant 4 on a cartesian coordinate system, i.e.

1  2  3  4  5  6  7  8...
2
3
4
5
6

The rows go down from the top of the screen increasing as you go down, while the columns increase
from left to right across the screen.  The top left coordinate, no matter what screen is 1, 1.
Also, if you use LOCATE with no other statements, nothing will result!  Remember you just moved
where text starts on a screen.  Usually LOCATE is used before a PRINT statement like the following:

LOCATE 5, 5
PRINT "Death to the Mystic's enemies!"

The output should look like the following:

=====begin output=====




     Death to the Mystic's enemies!
=====end output=======

That concludes the look at LOCATE


-Added 12/27/00-

CLS statement-completely clears the current screen

There is really not much more to say about it, but CLS is a useful statement for a few reasons.  
Run a program that PRINTs something a few times.  Note that when you run the program over and over
the previous output is still there!  Use the CLS statement at the top of your programs to clear 
all the previously outputted data in a fashion like this:

CLS
LOCATE 10, 10
PRINT "Hello"

There is some good stuff here!  Use a number between 0 and 2 (integers) after CLS and different 
screen parts will be cleared.  CLS 0 will clear the entire screen.  CLS 1 will clear the graphics
made on the screen.  CLS 2 will clear the text on the screen.

That concludes our look at CLS


-Added 1/5/00-

COLOR statement-changes color of text and/or highlight around text

Syntax is as follows:

COLOR colornumber, colornumber, colornumber

Depending on which SCREEN mode you are using (for right now you have been using SCREEN mode 0)
all of those commas might not be supported.  For example, SCREEN 13 supports only the first color
attribute, so it only changes text color and not the background.

You may be wondering now 'so what are the colors?' Here are the basic colors supported by most
SCREEN modes

0-Black
1-Dark Blue
2-Dark Green
3-Dark Cyan
4-Dark Red
5-Dark Magenta
6-Brown
7-Dark Grey
8-Light Grey
9-Light Blue
10-Light Green
11-Light Cyan
12-Light Red
13-Light Magenta
14-Yellow
15-Bright White

Many more things need to be noted.  When a SCREEN supports 3 attributes for COLOR (the only one is
screen 0) like COLOR 15, 9, 0 the first attribute represents the text color, the second the background
of the text, the third the screen color.  If only two attributes are given, like COLOR 15, 0 then
the first attribute is text color and the second is the highlight.  For only one attribute like 
COLOR 15, only text color is specified.

One last thing to note is that a COLOR statement alone does nothing.  It must be stated in conjunction
with a statement that gives output on the screen, like PRINT or LINE or PSET (we'll get to those later).
Such an example program would be:

CLS 2
COLOR 10, 15, 9
LOCATE 10, 10
PRINT "Stephen Hawking scares me"

The output text would be bright green, the texts bacground would be white, and the background of
the screen would be light blue, all at the 10th row and column starting.  Welp, that covers it for
COLOR, stay tuned next up's going to be getting into the real power in QB =)

Inputting Variables
-Added 1/14/00- INPUT statement- Prompts the user to input data Syntax is as follows: INPUT "text inside quotes", variablename OR INPUT variablename Before we explain actually what INPUTs do, we must explain what a proper variablename would be. Proper variable names have certain suffixes (special characters at the end) which tells whether it is text, or is a number, or an integer, or so on. For example, If you wanted the user to INPUT a string of text, you would use something like the following example: INPUT "Give me some text to eat by typing in something and pressing enter", EAT$ notice at the end a $ is placed. This signifies that variable EAT is text and that it is not numbers (you can still put numbers in there but you can't do any math with them). Here are the suffixes availible (that are useful and also about their limits and how much space they take up in the file $ - used for text - min 0 characters max 32767 characters-however many characters the string is % - integer - min -16383 max 16383-2 bytes & - long integer - min 2x10^-30 max 3x10^38 ! - single precision number - min -16383 max 16282-4 bytes @ # - double precision number - min -2x10^308 max 2x10^3508-8 bytes @ 14 places Ok, some of this info might now be right, I'll change it later, but that will suffice for now. Now ill give some examples of good variable names and evil ones that Qbasic yells at you for using =)- BillGatesSucks% Microsoftsucksingeneral# Metallicashouldstopbeingbabies$ =(- Bill Gates Sucks% Microsoft.sucks.in.general Metallicashouldstopbeingbabiesbutwhoisgoingtostopthem?imeanreally?theyrock$ Problems with each of the bad names now- 1. No SPACES! Qbasic will assume it is 3 different variablenames 2. No periods! periods also lead to problems because they are used in other forms in other things like TYPES 3. The string is waaaay too long, 40 characters is about as long as Qbasic will handle Here are a few more things to note: If you put a decimal place in an integer, only the integer part will show. An overflow will be given if you put in a number outside of its limits. Lastly, try to stray from double precision numbers which take up too much space and slow down the Program. One last thing to note: If your program uses a lot of integers use the command line DEFINT A-Z to speed up the program, and if your program uses a lot of strings use DEFSTR A-Z. Put these at the top of your program. Anyways back to inputting variables. If you want the user to be able to define his/her own variables use INPUT. Syntax is as follows: INPUT "text", variablename You can use any variable suffix with this statement, but now I bet you are wondering exactly how would you use this information the user provided for you in an effective non-wasteful manner? Combine it with other statements. One possible way of using the data is shown in the following example: INPUT "Tell me your name", name$ PRINT "Hello, "; name$ Output would look something like this: =====Begin Output===== Tell me your name (name) Hello, (name) =====End Output======= There are a few things to note. First of all, the user has to press enter for the data to go to the computer. Keep in mind most users are really impatient save for the old ones, and skimp on the input statments when they are not needed. There are several other ways to use INPUTted data, but the example above just shows you how to spit back out what the user just typed in. Next we'll take a look at testing for the user to INPUT certain pieces of data in. -Added 3.2.01- You've already learned one way to use INPUT statements but there are still several other ones. This chapter will mainly concern itself with the IF-THEN-ELSE block. IF-THEN-ELSE basically looks and sees whether the condition being checked is true, then if it is executes a command line, and if the statement is false, then it does another set of commands. Syntax is as follows: IF condition THEN commandline ELSE anothercommandline Of course if you need to execute more than one line for each THEN or ELSE statment then the syntax changes slightly to this: IF condition THEN commandline ELSE anothercommandline ENDIF ENDIF is necessary for IF-THEN-ELSE blocks because otherwise QBasic would not know when to stop executing lines and would generate an error.
Vote Now
1