|
After launching the QBasic interpreter (see before you start), you might see a window requesting a list of "parameters." If this window comes up, press the Enter key to continue. You should now see the QBasic interpreter, which has a blue background and displays a dialog box at the center. (If the interpreter fills the entire screen, then you may want to press "Alt + Enter," to make it smaller.) Press the Esc key to hide the dialog box. ![]() QBasic interpreter - main screen Type the following (including the quotation marks) in the QBasic interpreter:
Now press F5 to run the program. You should now see a black screen, with Hello World at the top, and Press any key to continue at the bottom. Press a key on the keyboard to return to the main screen. (The figure below displays the "output screen.") ![]() QBasic interpreter - output screen If you run the program again, the interpreter adds another Hello World. QBasic adds Hello World each time the program is run. Deleting the program To erase the current program:
Strings There are certain types of data (or information) called "strings." Strings contain a sequence of characters (letters, numbers, and symbols) enclosed in quotation marks. For example, "Hello World!" is a string. The following are also strings:
"This is a string" "abc123" "1 + 1 = 2" "!@#$%^&*()" Commands There are also special functions called "commands" (also called "instructions"). A "command" tells the QBasic interpreter to do something. The PRINT command tells the QBasic interpreter to print something to the screen. In this case, the interpreter printed "Hello World!".
With the PRINT command, you can also print numbers to the screen. Delete the current program (unless you already have) and write the following:
<press Enter>
Expressions An expression is something the interpreter calculates (or evaluates). Such as:
100 - 47 (returns 53) 3 * 34 (returns 102) 80 / 4 (returns 20) (100 * 3) + 56 (returns 356)
If you pass an expression to the PRINT command, the value returned (a number) is printed. Clear the current program, and then run the following:
If you enclose the expression with quotation marks, the expression becomes a string and isn't evaluated. For example:
More about the PRINT command You can use multiple print statements in your program.
PRINT "World"
World To place World onto the previous line, place a semi-colon after PRINT "Hello".
PRINT "World"
Also, if you put a comma instead of a semi-colon on the first line, the program will insert spaces between the two words.
PRINT "World"
Feel free to distribute this tutorial, upload it to your website, link to it from your site, etc. http://www.geocities.com/progsharehouse/qbtutor Mirror: http://development.freeservers.com/qbtutor |