Tutorial 1
< ------------------------------------------------------------------------------------------------------------------->

Welcome to tutorial number 1! In this tutorial, I will cover the resons why you should start programing with QBASIC, and I will also tell about some of the basic commands of QBASIC!!

The first thing I'm going to get to of course, is why you should even program. The first reason is that it's fun, and can come in handy. And, another reason is that if you start early, You will be a programing expert (if you keep at it) by the time you're a teenager. Now, You're probably thinking, "Why start with QBASIC?". Well, QBASIC is a fairly powerfull programing language, and it is pretty well the simplest! The commands are really easy to remember, and it is mostly a text based language, but don't worry, you can make full color games! Now, I may have convinced you by now, but if I haven't, this ought to: QBASIC is acually a offspring of BASIC, a early language made for beginers. Over the years, many, many different forms of BASIC have appeared over the years, most of them great. QBASIC is now the choice of most programers who are just starting, and I would recommend it for you, as well.

Now that I have given you the reasons to program with QBASIC, It is time to get you a QBASIC editor so that you can actually test your skills and have fun! Click HERE And then look at the bottom of the page. You should see 'QB WRITE 2.7 The best (and last) version of the QBASIC text editor:QBWrite.' (but it won't have the ' ' things) Click on it to download. However, even though it is a QBASIC editor, it may not be the complete version, so you may have to look further. An easier way is to get out the disk that comes with a windows 98 PC, dust it off, and then follow these instructions: click on browse this CD, and then next click on a file named TOOLS. Once that is done, open the file MSDOS(it may have a period in the name) and drag it to whatever file you want to save it to. You will most likely need this disk later to run it, so don't throw it away!

The Code

Ok, so i bet that you're now really eager to learn how to program computers, and I don't see why I can't start teaching you. So, the first order of buissness is to explain the basics... Well, that ought to be easy. First, all a program is is a detailed list of instructions that tell the computer what to do. The instrucions must include EVERYTHING!!!!! The instructions must include everything, because if you overlook even the tinyest little thing that even 3-year-olds know, the program will not do it. Now, the the first thing I'm going teach you how to do is how to print to the screen. It is awfully simple! All commands in QBASIC are in capital letters, and the print command is no exeption, so here is it printing Hello world! onto the screen: PRINT "Hello world!" .I told you it was simple! but, you're probably thinking Why the quotation marks? Well, the answer is is to tell QBASIC to print exactly what is in the. Without the quotation marks, QBASIC would think that you misspeled a command, and it would not let you continue until you fixed it. However, with the PRINT command, you don't get to chose where to print it, and I really think that stinks! Fortunatly, there is a way to chose where you're going to print. First of all, the screen will have 80 different coloms and 25 rows in which you can chose to print on. To actually use the comand, on the first line you would print LOCATE, and then you would press enter(to go down a line) and then you would put the PRINT "Your text here" comand afterwards. Here is an example that will print This is the middle in the middle of the screen:

LOCATE 12, 40

PRINT "This is the middle"

There, that was not to tough, was it? Of course not, but we have only just begun to learn QBASIC!

Now it is time to learn about variables. Variables are little spots of the memory that you can use until the program is exited. There are two types of variables: One type is a string variable, which can hold anything in it, but can not be used to hold numbers that you plan to do math with. The next type can only hold numbers, but the numbers can be used in calculations. If you are using something like a house address, I would recomend to put it in a string variable so that it does not get used in math by acident! Trust me, it gets confusing. Oh, and string variables always have a little $ sign on the end to tell the computer that this can hold anything in it(even though variables can be almost anything that is not a command!) Now, here is an example:

Height = 20

txt$ = "Here is that variable example!"

LOCATE Height, 13: PRINT txt$

In this example, it will print what the variable txt$ holds. And, as you can see in the example, txt$ holds the text Here is the variable example. Now, what about that Hight variable? Well, Hight is used in the LOCATE command. So, instead of putting the number 13 there, I put 13 in the variable Hight, and then told LOCATE to use whatever was in Hight. It may sound like a stupid waste of time to use variables, but they won't seem so stupid later, and I would recommend fooling around with them on that QBASIC edtor for a while, because you will use them in almost ever program that you make!!!!! THEY ARE VERY, VERY IMPORTANT!!!!!!!!!!

Loops

Now, all of that stuff is fine and dandy(mostly important, though!) but it is time to teach you about loops! The name pretty well explains it: All that they do is repeat lines of code. Now, this may not seem very important, but loops are up there with variables: There are almost no programs(exept the simple ones) that will not have loops and variables. There are two different types of loops:The normal one that goes for a certain number of times, and there are the ones that will go until you tell them otherwise(this is very useful for games!) !The first and easiest one to understand is the normal one, the one that goes for a certain number of times. For this one, it has a starting command and a continue/end command. The starting command is FOR and TO. These ones are used like this: FOR looping = 1 TO 10. That example would execute the next few lines of code for ten times, each time adding 1 to the variable looping. But, how do you tell it what code to repeat? Well, that is where the command NEXT comes in. Here is a example. The variable that gets looped is going to be Cool (just to prove that you can use any variable), and the code that is repeated will be PRINT "Hello world!(for the"; Cool "time!)!!!" Oh, and I forgot to explain... You can use the print command to show text and variables! (look on the example!!!!) Now, here is the example:

FOR Cool = 1 TO 10

PRINT "Hello world!(for the "; Cool "time!)!!!"

NEXT Cool

There, if you test that code, when you press F5 (to activate the program!), the screen should have the words:Hello world!(for the 1 time!)!!!! (and then it would go to the next point... Oh, and this part won't show on the program!) Hello world!(for the 2 time!)!!!! (and so on!). Now, the next type of loop is the DO loop. The commands for it are DO(instead of FOR) and then LOOP UNTIL Variable$ = "whatever"(instead of NEXT). In that example, it would loop until the variable Variable had "whatever" in it. Of course, since there is no mention of a variable called Variable, then that loop would go on forever! This is the type of loop used in games. How it is used is it keeps on playing the code in the game until the game code told the loop that the person had lost, so end the game. You'll get it! Well, that ought to show you how to do loops. If you didn't get it, email me at mddwebboy@msn.com. Now, there are two more commands that I plan to teach you in this lesson.

The INPUT command

Ok, now that I have covered how to make variables, use the PRINT command, how to make loops, and the LOCATE command, It is time to teach you the easiest way to get input from users! The command is the INPUT command, and it asks the user to write something, and then stores whatever the user wrote as a variable(but it usualy has to be a string($) variable!). Here is an example that will ask the user for his name, store whatever they wrote in a variable called nm$, and then print it ten times!

INPUT "What is your name"; nm$

FOR nmprint = 1 TO 20 STEP 2

PRINT nm$

NEXT nmprint

There! simple enough, but you're thinking: what was that STEP 2 thing? And didn't he say that it would only print 10 times? Well, the answer is that the STEP command makes QBASIC count by that many numbers. Example: FOR yadayada = 1 TO 70 STEP 8. For that loop, it would count by 8, so it would go 1, 8, 16, 24, 32, and so on. Get it? Now, back to the INPUT command. You can also go:

PRINT "What is your name";

INPUT nm$

That one works pretty well, I would say, but it is not as efficent as the other one.

The IF command

Now, another command is the IF command. What it does is it looks at a variable and if the variable is the same as the one the IF command wants it to be, the IF command does something. In this example, the IF command will tell the computer to print "Ok, you typed Yes, so I have to go yada, yada, yada!" if you print yes, and it will print "Oh, man, you typed No! WAAAAaaaa......WHA!" if you type anything else.

INPUT "Type Yes if you want me to sing, and No if you don't. So, which one"; UsAnswer$

IF (UsAnswer$ = "Yes") THEN

PRINT "You typed Yes, so I have to say Yada, Yada, YADA!!"

ELSEIF (UsAnswer$ = "No") THEN

PRINT "Oh, you typed no! WAAAAAAAAaaaaaaa......WHA!!!"

ELSE

PRINT "What did you say? It wasn't Yes or No...."

END IF

The SOUND command

Now, we have learned the basic output things in QBASIC(for the screen, I mean), But there is still a lot to do. I have to teach you to make sound and to make better graphics (actual color animation)! To wrap up this tutorial, I'm going to teach you the SOUND command. The SOUND command only works on windows that are older than 98, but I'm not shure about macotosh..... Oh, well! The sound command needs you to tell it two things before it will activate. First, you need to tell it how long to play th sound(a second is 18.2), and then you need to tell it what tone to make(I think the limits for that are 50 to 32767..... : P ). It goes like this: SOUND 500, 18.2 . That would sound the tone 500 for one second. Loops also come in handy for that:

FOR Note = 50 TO 2000 STEP 25

SOUND Note, 9.1

NEXT Note

See what I mean?

Be careful not to mix up the IF and FOR commands the wrong way, or a error message will appear!!!!

Well, that wraps up tutorial no. 1. If you have any questions or comments, email me at mddwebboy@msn.com. Oh, and if you can't read this tutorial(or any others!) because it is spelled bad....

TO BAD!!!

Yahoo! Games
Tutorials Home
< ------------------------------------------------------------------------------------------------------------------->