Site hosted by Angelfire.com: Build your free website today!


A BEGINNERS GUIDE TO UNDERSTANDING
AND USING QBASIC


QBASIC is short for Quickbasic. It is a computer programming language invented by Microsoft. It is an interpreted language. That means it is scanned line by line each time it is run. To load QBASIC, click on the Start menu (Windows 95/98/2000/ME/XP) and then click on Run. Next type Qbasic in the Open/Run window. Within seconds a blue screen should appear. If this doesn't happen, you can always locate it under usually C:\DOS\QBASIC.EXE. Just type that line into the Run window. Using QBASIC you can write easy structured code that looks both professional and extremely logical. Let's suppose you want QBASIC to print a line that greets you (the typist or user) and then asks for your name. Try entering this code in QBASIC:

'********************************
'* This is an example QBASIC program *
'********************************

DIM Name$(20)
LOCATE 2,2:PRINT "Please tell me what your name is.";
LINE INPUT Name$
PRINT "Hello ";Name$;". This is QBASIC."
Click to see an example QBASIC program.

Click here to learn about game programming.


Here's how it works. On the first line DIM Name$(20) we have dimensioned a string called Name$. You can visualize a string like a bunch of letters being tied together by a plus sign. Like this: N + a + m + e. When you delete the plus signs and combine the letters, you get the word Name Does this clarify how a string works for you now? Also notice that the string Name$ is set to a specified length of 20. The gives QBASIC a place to hold up to 20 characters. The reason for this is that some people have longer names. Lets suppose that the string Name$ contains a name called Alexander What would be the total length? If you guessed 9, then you are correct. Just count the letters in the name Alexander.

Now look at the next statement
CLS . This just informs QBASIC to clear the screen. Its used to erase leftover "garbage" or messages that appear on the display. On the next line LOCATE 2,2:PRINT "Please tell me what your name is."; the LOCATE 2,2 tells QBASIC to position the cusor at 2 spaces down from the top of your screen and 2 spaces over from the left of your screen - LOCATE 2,2. The next character (the colon : ) is used as a separator. It advises QBASIC that another statment will be followed after the colon. Therefore the next statement PRINT "Please tell me what your name is."; will simply print the message Please tell me what your name is. across the screen. The quotes surrounding the message, Please tell me what your name is, will never be displayed. They are used to indicate that this is a string (can contain any characters, including both numbers, characters (exception with the quotes however) and anything you can type inside the two quotation marks. Finally, at the end of the line, the semicolon is used to compress the text on the same line. If you omit the semicolon, then the next characters following after the word is." will appear exactly beside the word is.

As we examine the next line
LINE INPUT Name$ you should understand that this will create a text entry prompt. Think of this like the MS-DOS prompt. It will wait for you to enter in some text and then hit enter. It works the same way. This statement is waiting for you to type in a name and then it is saved into the Name$ string. For example, if you type in Cynthia the string Name$ will contain Cynthia . Remember the string of letters stringing together a word C+y+n+t+h+i+a for easier reference.

Finally that brings us to the last line
PRINT "Hello ";Name$;". This is QBASIC."
The PRINT command will print everything beyond it. So if the string Name$ contained Cynthia then the line would print like this:
Hello Cynthia. This is QBASIC. The program has embedded the name Cynthia inside of the entire PRINT message. Run the program again. This time enter the name, Jennifer. The program would easily replace the name Cynthia with Jennifer.


Return to Homepage Vist Qbasic downloads Find help with Qbasic Learn about the architecture of logic Check out the new Visitor's Page!