In this appendix, we'll examine the position of Visual Basic as a programming language by taking a somewhat closer look at high-level and low-level languages, with some examples for comparison.
A low-level language is characterized by its ability to manipulate the computer's operating system and hardware more or less directly. For instance, a programmer who is using a low-level language may be able to easily turn on the motor of a floppy drive, check the status bits of the printer interface, or look at individual sectors on a disk, whereas these tasks may be difficult, if not impossible, with a high-level language. Another benefit of low-level languages is that they tend to perform tasks more quickly than high-level languages.
On the other hand, the power to manipulate the computer at a low level comes at a price. L ow-level languages are generally more cryptic—they tend to be farther removed from ordinary spoken languages and are therefore harder to learn, remember, and use. High-level languages (and application-level languages, which many people would refer to simply as high-level languages) tend to be more user-friendly, but the price we pay for that friendliness is less control over the computer and slower running programs.
To illustrate, consider the task of printing some text. A low-level language may only be able to send individual characters to a printer. The process of printing with a low-level language might go something like the following:
Check the status of the printer.
If the printer is free, initialize the printer.
Send a character to the printer.
Check to see if this character arrived safely.
If not, send the character again.
If so, start over with the next character.
The "lowest" level language that programmers use is called assembly language . Indeed, assembly language has essentially complete control over the computer's hardware. To illustrate assembly language code, the following program prints the message "Happy printing." Don't worry if these instructions seem meaningless—you can just skim over them to get the feel. In fact, the very point we want to make is that low-level languages are much more cryptic than high-level languages. (Lines that begin with a semicolon are comments. We have left out error checking to save a little space.)
; -------------------- ; Data for the program ; -------------------- ; message to print Message DB 'Happy printing', 0Dh, 0Ah ; length of message Msg_Len EQU $-Message ; -------------------- ; Initialize printer 0 ; -------------------- mov ah,1 mov dx,0 int 17h ; --------------------- ; Printing instructions ; --------------------- ; get number of characters to print mov cx,Msg_Len ; get location of message mov bx,offset Message ; get printer number (first printer is printer 0) mov dx,0 Print_Loop: ; send character to printer 0 mov ah,0 mov al,[bx] int 17h ; do next character inc bx loop Print_Loop
For comparison, let us see how this same task would be accomplished in the BASIC programming language:
LPRINT "Happy printing"
The difference is pretty obvious.
As we have discussed, high-level languages are usually designed for a specific purpose. Generally, this purpose is to write software applications of a specific type. For instance, Visual C++ and Visual Basic are used primarily to write standalone Windows applications. Indeed, Microsoft Excel itself is written in Visual C++. As another example, FORTRAN (which is a contraction of Formula Translation) is designed to write scientific and computational applications for various platforms (including Windows). COBOL is used to write business-related applications (generally for mainframe computers).
At the highest level in the programming language hierarchy, we find programs such as Excel VBA, whose primary purpose is not to manipulate the operating system or hardware, nor to write standalone Windows applications, but rather to manipulate a high-level software application (in this case Microsoft Excel).
Just for fun, let us take a brief look at a handful of the more common programming languages.
The word BASIC is an acronym for Beginners All-Purpose Symbolic Instruction Code, the key word here being Beginners. BASIC was developed at Dartmouth College in 1963, by two mathematicians: John Kemeny and Thomas Kurtz. The intention was to design a programming language for liberal arts students, who made up the vast majority of the student population at Dartmouth. The goal was to create a language that would be friendly to the user and have a fast turn-around time so it could be used effectively for homework assignments. (In those days, a student would submit a program to a computer operator, who would place the program in a queue, awaiting processing by the computer. The student would simply have to wait for the results—there were no PCs in the 1960s!)
The first version of BASIC was very simple; indeed, it was primitive. For example, it had only one data type: floating-point. (Data types are discussed in Chapter 5.) Since then BASIC has made tremendous strides as a personal computer programming language, due mostly to the embrace of the language by Microsoft.
Even to this day, however, the BASIC language, and its offshoot Visual Basic, do not get much respect among computer scientists or academicians. The BASIC language gets a bad rap on two fronts. First, it is generally considered a weak language in the sense that it does not provide very much control over the computer's hardware (or operating system), at least as compared to other languages such as C. Second, BASIC has a reputation for not "forcing" (or in some cases even allowing) programmers to use good programming style.
For comparison with some other languages, here is a BASIC program that asks the user for some numbers and then returns their average. Lines beginning with an apostrophe are comment lines that are ignored by the computer.
' BASIC program to compute the average ' of a set of at most 100 numbers ' Ask for the number of numbers INPUT "Enter the number of numbers: ", Num ' If Num is between 1 and 100 then proceed ' IF Num > 0 AND Num <= 100 THEN Sum = 0 ' Loop to collect the numbers to average FOR I = 1 TO Num ' Ask for next number INPUT "Enter next number: ", NextNum ' Add the number to the running sum Sum = Sum + NextNum NEXT I ' Compute the average Ave = Sum / Num ' Display the average PRINT "The average is: "; Ave END IF END