|
QBasic Immediate Mode Use
Lesson Objectives |

|
The primary purpose of this lesson is to introduce you the the "mechanics" of
using the QBASIC programming environment.
After completing this lesson, you should be able to:
- Create a desktop shoutcut to the QBASIC program
- Configure the QBASIC window
- Activate the QBASIC program
- Accomplish simple arithmetic calculations in the immediate mode
- Begin to understand the priority of arithmetic operators as implemented in QBASIC
- Understand the use of the PRINT keyword
- Exit the QBASIC program
|
|
Note:
|
You will experience some differences when you run QBASIC under Windows NT and
when you run it under Windows 95/98. Be aware of this fact should you encounter
differences between your experiences and those described on this page.
|
Creating a QBASIC Shortcut
The foundational assumption for this lesson is that you have QBASIC
installed on your computer, and have a shortcut icon for this program
located on your desktop. The figure at right and below, illustrates the
appearence of the QBASIC shortcut icon on my computer.
If you have QBASIC installed on your computer but do not have a shortcut
icon, point your mouse pointer to a blank part of the desktop and right-click.
From the resulting pop up menu, select New and Shortcut.
A dialog box will appear on your screen. In the text field which appears
in the center of this dialog box, simply type QBASIC.EXE and then
click on the Next button. If you see a message box that indicates
that the QBASIC.EXE program cannot be found, cancel out of this approach and
use the Find command (found on the Start Menu).
Once the Find command has located the QBASIC.EXE file on your
computer, simply use the right mouse button to drage the file onto your
desktop and create a shortcut. If you have difficulty with either of these
approaches, contact your instructor for assistance. Obviously, you will
need to have access to the QBASIC program before you can do any of the
programming examples presented in this and later lessons.
Getting Starting
Once the QBASIC shortcut has been created, simply doubble-click on it
to activate the program development environment. When you first activate
the QBASIC program, the window illustrated below should appear. Press
the Esc key to clear the copyright dialog box.
|
If you get a full-screen display instead of a window, you can change to
the windowed display by right-clicking on the QBASIC icon prior to
activating the program and then selecting Properties from the
pop up menu. When the QBASIC Properties dialog box appears, select
the Screen tab, and the dialog box should appear as illustrated at right.
To specify a windowed display, click the radio button in front of Window
in the Usage area of the dialog.
The QBASIC windows illustrated on this page have the Display toolbar
selected. If you do not want the toolbar displayed, remember to uncheck
the corresponding checkbox (shown at right).
|
|
After you press the Esc key, the QBASIC screen will appear as shown
in the figure below. Note the location of the cursor (the underscore character)
in the upper left corner of the program code portion of the display. If you begin
to type QBASIC code, it will appear at the cursor location.
We will return to this part of the screen later. For now, we can get a "taste"
of QBASIC by using what is called the "immediate mode." In this mode, we will
type QBASIC instructions that are "immediately" executed. This allows us to see
the results immediately, and to better understand how the instructions function.
The figure bellow reflects the fact that the cursor has been moved to the immediate
(lower) portion of the QBASIC screen.
In the figure below, the QBASIC output instruction (print) is being used
in the immediate mode to direct the computer to display the results of the arithmetic
expression 2+2/2. What do you predict the result will be?
This is the output display for QBASIC. Whenever output is produced in the immediate
mode (or by an executing program) this display will replace the QBASIC editing screen.
In this figure, you see the ansere to the simple arithmetic expression 2+2/2. Is
the answer what you expected?
If you expected the answer to be 2, it was because you thought that the computer would
first calculate 2+2, yielding 4 and then 4/2 yielding 2. However,
the QBASIC interpreter uses a priority of arithmetic operators to make certain it gets
consistent results. In this case, since the rules of this priority of operators determine
that division has a higher priority than addition,
the computer first calculates 2/2 to get 1 and then calculates 2+1
to get 3 (the "correct" answer).
As shown at the bottom of the output screen illustrated above, to return to the
programming environment you simply press any key on the keyboard. If you have
difficulty selecting a key as "any key" just press Enter.
In the figure below, the immediate mode area of the programming environment has been expanded by "dragging" the
dividing line upward using the mouse pointer. This allows more immediate mode instructions
to be displayed in the sequence they were typed. As you type these commands and press the Enter key, nothing
will (appear to) happen until you issue an instruction which calls for output. Only then
will the output display (the black screen) appear and show the desired output.
In the figure below, it is important to
note that the output screen "remembers" the sequence of output results, in this case
the three print instructions that were in the sequence above.
When you are finished using QBASIC in the immediate mode, you may exit the program
by using your mouse to click on File and Exit. This is illustrated in the figure below.
|