Programming Reference: Useful QBASIC Commands

Z. Perry
QBASIC is a programming language which is useful for creating many types of programs to run in Windows and DOS. It features a massive number of commands, some of which produce effects which can be achieved using other QBASIC commands in different ways. Even advanced programmers usually don't know all of them, as some are only necessary in specific types of programs. Read on to learn about some of the most frequently useful commands; simply type them in the QBASIC programming interface and press F1 if you need more details on their syntax and parameters...

CLS: Clears the screen of all text and graphics. No parameters are needed.

COLOR: Specifies the color scheme to be used; it is followed by two color numbers (COLOR ,) separated by a comma. For example, "COLOR 7,1" changes the color to white over blue.

END: With no parameters, this QBASIC command simply ends the program; it is not necessary to use END on a program's last line, in which it automatically ends, but can be useful for allowing users to exit the program.

FOR/NEXT: The FOR and NEXT commands require a set of program lines to be repeated a specific number of times. The FOR command starts the loop, while NEXT sends the program back to the command following FOR.

GOTO: Used to change to a different position in the QBASIC program code, usually identified by a line number. For example, "GOTO 75".

IF/THEN: The IF and THEN commands activate a particular function or change to a different line number if a particular statement is true, such as: IF DATE$="12-25-2007" THEN PRINT "Merry Christmas!"

INPUT: This useful programming command lets the user enter data which is to be stored in a variable, and may include a prompt. It can also be utilized to read data from an open file.

LOCATE: Moves the cursor to a specified row and column on the screen.

PRINT: This QBASIC programming command, unlike its name suggests, displays text or variable data on the screen. The text should follow it in quotation marks. It can also save data to open files.

RANDOMIZE: Very useful for all programs with commands involving random numbers, using "RANDOMIZE TIMER" prevents random numbers from being the same each time the program is used.

SCREEN: Changes to the QBASIC screen mode identified by the number following the command, as in "SCREEN 9". Different modes have varying text styles, graphics resolutions, and video card/adapter requirements; Windows XP can only use the default mode (zero).

SHELL: Without parameters, SHELL lets the user access the DOS command prompt until he or she types "EXIT", after which the program resumes. On the other hand, it can be followed by a single command to activate, like: SHELL "DIR".

The programming commands and reference instructions provided are based upon QBASIC version 4.5.

Published by Z. Perry

Freelance writer, website operator, and programmer  View profile

1 Comments

Post a Comment
  • VIDYA VINOD2/2/2009

    VERY USEFUL SITE !

To comment, please sign in to your Yahoo! account, or sign up for a new account.