Last updated: 4/16/03
Link back to course Welcome...
Background
In the early days of computers, most people wrote and ran their own programs. This led to the conclusion that everybody that was going to use a computer needed to learn how to program. Courses like "Computers and Society" were substantially about programming.
Now, however, it is clear that most people who use computers are not programmers, but use programs (applications) written by others; programs such as word processors, spreadsheets and database programs. Today, some of these can involve programming. Here, building formulae in Excel, and with the Paper and Pencil Computer, you have had some experience with programming. Even major word processors such as Microsoft Word contain built-in programming languages for customizing work. Usually, however, anything substantial is done by specialists within an organization. It can still help to understand something about programming. But this is nowhere near the amount of programming that was done to create the applications.
What is a Computer Program?
A computer program is a list of instructions for a computer to execute. Most programming is done, not using the binary computer instructions directly, but in a symbolic language that can look a little bit like English. Even in the Paper and Pencil Computer, the original concept was to use the binary codes (three binary digits) for the instructions, but we have replaced that with the higher-level equivalent. For example, STOP was 000, the next instruction ADD was 001 and the third instruction SUB was 010, counting in binary.
With a standard higher-level program, there are two program files (and sometimes more): the file with the binary codes, also called "machine lagnuage," that the computer could execute (the "executable" file with the exe extension, but other variations are used in addition) and the "source file" with the English-like words. The programmer writes the source file, which usually has one instruction per line, and the computer translates that into the executable file, using a computer program that can be called either an "assembler" or "compiler." In this case, the entire program is translated into binary codes or machine language, and then executed all at once.
In an alternate scheme, there is only a source file, and the source file is compiled into machine language line by line, as it is executed. This is slower, but for short programs it can be more convenient, and since computers are so fast today, can still run quickly in terms of human reaction times. In this case, the computer program that does the translation from source code to machine language is called an "interpreter." In the case of interpretation, the source program is translated into machine language line by line on the fly as it is executed, and there is no machine language file.
Here you will examine some pre-written programs to see how they work, using the QBASIC interpreted programming language. DOS always came with a built-in programming language. Earlier DOS versions came with GWBASIC, but later, QBASIC became the standard. Early versions of Windows came with a programming language, but starting with Windows 95, programming languages became for-sale add-ons.
Programming has several steps:
QBASIC is designed for small programs and quick results. It has one outstanding feature for beginners; each program line is checked for syntax after you leave the line with <Enter> or the up or down arrow keys. It may not do what you want, but the check ensures that it is legal. If the line is OK, it is put into a standard format with:
If the line is not legal, there is no change from the way you typed it; this is a signal to look for a problem and edit the line to fix the problem(s).
Notice that if you enter lines already in the standard format, there will be no change if the line is legal. Therefore, it pays to enter lines without spaces around the operators, and with the keywords in lowercase.
Downloading QBASIC:
To use QBASIC, you need two files: Qbasic.exe which is the program that you run to use the Qbasic programming language, and the help file Qbasic.hlp. You can download both of these, one at a time, from the GST 2710 web site at http://www.cll.wayne.edu/isp/gst2710.
Remember to right-click on the link to each of these files!!!!!
It is convenient to save them to your computer desktop, which you can select
in the "Save As..." dialog by clicking the "up the path"
icon several times until "Save In" shows "Desktop" as in the
figure below (your screen may look slightly different, depending upon your
Browser, Browser version, and Windows version):
Starting QBASIC:
When QBASIC starts, tap the <Esc> key to clear the opening dialog, unless you want to read the background help information.
Using QBASIC:
You may be able to use the mouse with QBASIC menus. QBASIC menus are very similar to Windows menus. Unlike Windows, the mouse cursor starts off the screen on the left. Move the mouse to the right to bring the cursor onto the screen.
To use the QBASIC menus on the lab computers, first hit the <Alt> key. This will highlight the menu items. (If you hit <Alt> by mistake, you can hit <Esc> or <Alt> again to cancel and return to the screen.) To pull down a menu item, such as File, type its first letter (white when menus are highlighted). With the menu subitems pulled down for display, move up and down with the corresponding arrow keys. When the item you want is highlighted, hit <Return> to choose it.
The programming screen is blue by default; the help screens are black.
In QBASIC, like most high-level programming languages, the programmer keeps tracks of variables by symbol (e.g. x) instead of by the numerical address of the location. QBASIC keeps track of the addresses.
QBASIC has several types of values it can store and work with. Here, these are specified by the last character of the variable name, as follows:
On a program line, anything after a single quote (') is treated as a comment and ignored. You will use this as part of the assignment.
(NOTE: Below, for a key with a word label, such as Esc, the key is shown as <Esc>. If you see the angle brackets <> they enclose the text on the key.)
CLS
PRINT "C:> ";
DO WHILE (2 > 1)
j$ = INKEY$
IF (LEN(j$) = 1) THEN
IF (ASC(j$) = 27) THEN STOP
PRINT j$;
END IF
LOOP
NOTE: you will have to use <Esc> to end this one.
CLS
PRINT "C:> ";
DO WHILE (2 > 1)
j$ = INKEY$
IF (LEN(j$) = 1) THEN
IF (ASC(j$) = 27) THEN STOP
IF (j$ <> " ") THEN j$ = CHR$(ASC(j$) + 1)
PRINT j$
END IF
LOOP
NOTE: you will have to use <Esc> to end this one.
s$ = "Help, I'm a prisoner inside this computer. " ' Set up line for display
j% = LEN(s$)
i% = 0
CLS
PRINT "C:> ";
DO WHILE (2 > 1)
k$ = INKEY$
IF (LEN(k$) = 1) THEN
IF (ASC(k$) = 27) THEN STOP
i% = i% + 1
IF (i% > j%) THEN i% = 1
PRINT MID$(s$, i%, 1);
END IF
LOOP
NOTE: you will have to use <Ctrl>c to end this one;
There are many QBASIC commands and keywords. To learn about one, click on Help, double-click on Index and type the first letter of the keyword. Then double-click on the one you want to read about. To leave Help, hit <Esc> to get back to the programming screen. Here are the keywords we will be using: