Qbasic Tutorial: Part I. Ver 1.0 by Ryan Lin Getting Started: First off, you need a Qbasic compiler to program in Qbasic. You can find one in QB4all (listed in the links section of the Qbasic section.) After downloading (into windows (I prefer)) You can run the compiler and start programming. If you ever need help with programming, e-mail me at rjlstar@yahoo.com Here are the basics of running the Qbasic compiler: F5 - Run your program Ctrl + Pause/Break - End a un-ending program Saving - You may save your programs in .BAS or .TXT form Output Screen - the screen you use when a program is being ran Input Screen - the screen you type code in. (do not write "input" when you see it in the tutorial) Syntax - The way you write codes along with words you enter. Commands: (I don't really think the order of the commands you know really affects how you interpret the meaning of each command. The way I learned QB was to learn all the commands I have listed first before starting to program.) CLS - Wipes the screen with the color you set as the backgroung. I suggest putting this command at the beginning of each program to clear earlier programs leftovers. REM - This is an abbreviation for remark. The syntax is: REM notes. Anything after the REM command up to the end of the line is ignored by the Qbasic compiler. REM is used to take notes while writing a program and to help the programmer keep track of what parts of a program or variables stand for. Example: Input: REM enter some notes here PRINT "QB ignores text after the REM command" Output: QB ignores text after the REM command Neat Tricks : The REM command may be replaced with the "aposterphy" command: '. Aposterphies stand out more than REM so I advise programmers to use them instead of REM. Example: Input: 'notes Output: (nothing) SCREEN - This command sets the screen number. Different screens enable different abilities. The syntax for SCREEN is: SCREEN ScreenNumber. Below are the specifications of each screen: SCREEN 0: Text mode only 40 x 25, 40 x 43, 40 x 50, 80 x 25, 80 x 43, or 80 x 50 text format, 8 x 8 character box (8 x 14, 9 x 14, or 9 x 16 with EGA or VGA) 16 colors assigned to any of 16 attributes (with CGA or EGA) 64 colors assigned to any of 16 attributes (with EGA or VGA) Depending on the text resolution and adapter, 8 video memory pages (0-7), 4 pages (0-3), 2 pages (0-1), or 1 page (0) CGA, EGA, VGA, or MCGA Adapters SCREEN 1: 320 x 200 graphics 40 x 25 text format, 8 x 8 character box 16 background colors and one of two sets of 3 foreground colors assigned using COLOR statement with CGA 16 colors assigned to 4 attributes with EGA or VGA 1 video memory page (0) SCREEN 2: 640 x 200 graphics 80 x 25 text format, 8 x 8 character box 16 colors assigned to 2 attributes with EGA or VGA 1 video memory page (0) Hercules, Olivetti, or AT&T Adapters SCREEN 3: Hercules adapter required, monochrome monitor only 720 x 348 graphics 80 x 25 text format, 9 x 14 character box Usually 2 video memory pages (0-1); 1 page (0) if a second color display adapter is installed PALETTE statement not supported Invoke the Hercules driver MSHERC.COM before using screen mode 3 SCREEN 4: Supports Olivetti Personal Computers models M24, M240, M28, M280, M380, M380/C, and M380/T and AT&T Personal Computers 6300 series 640 x 400 graphics 80 x 25 text format, 8 x 16 character box 1 of 16 colors assigned as the foreground color (selected by the COLOR statement); background is fixed at black 1 video memory page (0) PALETTE statement not supported EGA or VGA Adapters SCREEN 7: 320 x 200 graphics 40 x 25 text format, 8 x 8 character box Assignment of 16 colors to any of 16 attributes If 64K EGA adapter memory, 2 video memory pages (0-1); otherwise, 8 pages (0-7) SCREEN 8: 640 x 200 graphics 80 x 25 text format, 8 x 8 character box Assignment of 16 colors to any of 16 attributes If 64K EGA adapter memory, 1 video memory page (0); otherwise, 4 pages (0-3) SCREEN 9: 640 x 350 graphics 80 x 25 or 80 x 43 text format, 8 x 14 or 8 x 8 character box 16 colors assigned to 4 attributes (64K adapter memory), or 64 colors assigned to 16 attributes (more than 64K adapter memory) If 64K EGA adapter memory, 1 video memory page (0); otherwise, 2 pages (0-1) EGA or VGA Adapters, Monochrome Monitor Only SCREEN 10: 640 x 350 graphics, monochrome monitor only 80 x 25 or 80 x 43 text format, 8 x 14 or 8 x 8 character box Up to 9 pseudocolors assigned to 4 attributes 2 video memory pages (0-1), 256K adapter memory required VGA or MCGA Adapters Screen 11 (VGA or MCGA) 640 x 480 graphics 80 x 30 or 80 x 60 text format, 8 x 16 or 8 x 8 character box Assignment of up to 256K colors to 2 attributes 1 video memory page (0) Screen 12 (VGA) 640 x 480 graphics 80 x 30 or 80 x 60 text format, 8 x 16 or 8 x 8 character box Assignment of up to 256K colors to 16 attributes 1 video memory page (0) Screen 13 (VGA or MCGA) 320 x 200 graphics 40 x 25 text format, 8 x 8 character box Assignment of up to 256K colors to 256 attributes 1 video memory page (0) Neat Tricks: The SCREEN command may be left out. The default SCREEN is SCREEN 0. COLOR - Sets color of the foreground, background, and border. The syntax is: COLOR foreground, background, border. For most screens this is the syntax. The code numberes for the color are listed below: 00 = jet black 01 = navy blue 02 = dark muddy green 03 = dark aqua 04 = dark vivid red 05 = dark purple 06 = light orange brown 07 = light grey 08 = dark grey 09 = sky blue 10 = light grass green 11 = light sea aqua 12 = light pinkish red 13 = magenta/ light purple) 14 = vivid yellow 14 = snow pure white Example: Input: COLOR 04, 01, 11 PRINT "this will have red text, blue background, aqua border" Output: this will have red text, blue background, aqua border (visualize the color) LET - This Assigns a value to a variable. The syntax is: Let "variable = valueT" T could be one of five variable types: 1.) $ - string. Example: HI 2.) % - integer. Example: 5 3.) & - long integer. Example: 55555 4.) ! - single integer. Example: 55.5555 5.) # - double integer. Example: 555555.55 variable could be 2 types of things: 1.) A String, integer, long integet, single integer, or a double integer 2.) A mathematical expression. Example: LET three = 1 + 2 Example: Input: Let MyName$ = "ryan" PRINT MyName$ Output: ryan Neat Tricks: The LET command can be ommitted! You can leave it out and the varibles will still be assigned. It is suggested that LET be ommitted because it will conserve space. $,%,&,!, and # may also be ommitted, but sometimes it is wise to specify what type a variable is to conserve space. PRINT - This displays characters on the first line of the output screen. using the print command more then once puts characters in a stack each belew each other. Example: Input: Print "hi" Output: hi Print also displays the value assigned to a variable Example: Input: Let A = 5 Print "this is what is in A:" Print A Output: this is what is in A: 5 Neat Tricks: Input: Let Name$ = "Ryan" Print "hello " + Name$ " ,good morning" Output: hello Ryan ,good morning END - Ends a program. "Press any key to continue" will appear on the bottom of the screen. Press any key to go back to the Qbasic editor. INPUT - Stores user input into a variable. The syntax is: INPUT variable. When this command is used, a question mark will apear. The user enters a value and presses enter to confirm the value into the variable Example: Input: INPUT variable$ Print "you typed in: " ; variable$ Output: ?typeINsomething you typed in: typeINsomething Neat Tricks: You may enter text before the input. Example: INPUT "type in something" ; variable$ GOTO - The GOTO command searches for a line label and presumes the program at that point. The syntax is: GOTO label. (a line label may be a word followed by a colon or a number.) Example: Input: begin: PRINT "this text will print infinite amount of times" GOTO begin Output: this text will print infinite amount of times this text will print infinite amount of times this text will print infinite amount of times (and so on...) FOR/ NEXT - This pair command repeats commands within the FOR and NEXT command a specified number of times. The syntax is: FOR variable = BeginningNumber to EndNumber STEP increment EnterCommandsHere NEXT variable Example: Input: FOR I = 1 TO 6 STEP 2 PRINT "this text appears three times because you count to: six in twos" NEXT I Output: this text appears three times because you count to: six in twos" this text appears three times because you count to: six in twos" this text appears three times because you count to: six in twos" Neat Tricks: The STEP command may be ommitted. (this will make the increment the default {1}) The STEP command may also be a negative increment. IF/ THEN - Checks if statement is true or false, then carries on with specified commands. The syntax is: IF statement THEN commands. This means if the statement is ture then carry out the commands. Example: Input: IF 1 = 1 THEN PRINT "1 is obviously equal to 1" Output: 1 is obviously equal to 1 Closing This is the end of part one to my massive tutorial for intermediate/ advanced tutorial. Try out a these commands before going onto part II. Part II has commands not commonly used but sometimes used in specific algorithms. Part III will have techniques of advanced Quick Basic. This tutorial was finished August 8, 2001 by Ryan Lin