📄 vel01.htm
字号:
<P>Large-scale programming tool improvements did not occur until a hardware breakthrough occurred: NASA's space efforts developed the microchip, and microcomputers were born. Now, instead of new and potential programmers, desktop computers opened the door for millions of would-be programmers. These programmers demanded easier programming tools.<BR><BLOCKQUOTE><BLOCKQUOTE><HR ALIGN=CENTER><BR><NOTE><I>Definition: QBasic</I> is a recent BASIC language clone.</NOTE><BR><HR ALIGN=CENTER></BLOCKQUOTE></BLOCKQUOTE><P>Efforts were made to improve the friendliness of programming languages like BASIC. New versions of BASIC, such as QBasic, enabled programmers to write more powerful programs with less effort. Programmers could also write programs that had a less rigid style than those before. Listing 1.3 shows a QBasic version of the payroll calculation shown in the previous two listings. As you can see, the language is getting less strict and more free-form.<BR><P><FONT COLOR="#000080"><B>Listing 1.3. A QBasic program.</B></FONT><BR><PRE><FONT COLOR="#000080">TaxRate = .25PRINT "** Payroll Calculations **"PRINT "** Enter the employee's ID, hours, and pay rate"INPUT IdOfEmp$, HrsWorked, RateDO UNTIL (IdOfEmp$ = "END") IF (HrsWorked <= 40) THEN ' *******Compute regular pay GrossPay = HrsWorked * Rate ELSE ' *******Compute overtime pay OverTimeHours = HrsWorked - 40 OverTimeGross = OverTimeHours * Rate * 1.5 GrossPay = 40 * Rate + OverTimeGross END IF Taxes = GrossPay * TaxRate PayNet = GrossPay - Taxes PRINT "Emp: "; IdOfEmp$; "Net Pay:"; PayNet INPUT IdOfEmp$, HrsWorked, RateLOOPEND</FONT></PRE><BR><A NAME="E69E15"></A><H4 ALIGN=CENTER><CENTER><FONT SIZE=4 COLOR="#FF0000"><B>You Run Programs to Produce Output</B></FONT></CENTER></H4><BR><BLOCKQUOTE><BLOCKQUOTE><HR ALIGN=CENTER><BR><NOTE><I>Definition: </I>Computers generate <I>output</I> on screens and printers.</NOTE><BR><HR ALIGN=CENTER></BLOCKQUOTE></BLOCKQUOTE><P>Just as a recipe has a result, the cooked meal, instructions in a program produce an important result. The result of the programming effort is the finished program that makes the computer perform a directed task, such as payroll processing. After entering a program or loading a program from the disk, you must tell the computer to run, or execute, the program. The computer then follows the program's instructions and produces the output.<BR><P>If you entered the code in Listing 1.3 into the QBasic programming language, the following output might result:<BR><PRE><FONT COLOR="#000080">** Payroll Calculations **** Enter the employee's ID, hours, and pay rate? <B>KL823, 40, 9.25</B>Emp: KL823 Net Pay: 277.5? <B>PO341, 35, 10</B>Emp: PO341 Net Pay: 262.5? <B>LP543, 40, 10</B>Emp: LP543 Net Pay: 300? <B>END, 0, 0</B></FONT></PRE><BLOCKQUOTE><BLOCKQUOTE><HR ALIGN=CENTER><BR><NOTE><B>Note: </B>The previous QBasic code requires that the user tell the program that there are no more employees to process by typing END as an employee ID and zero amounts for the hours and pay rate.</NOTE><BR><HR ALIGN=CENTER></BLOCKQUOTE></BLOCKQUOTE><BLOCKQUOTE><BLOCKQUOTE><HR ALIGN=CENTER><BR><NOTE><B>Tip: </B>This output would be different if the user entered different data, because the program would calculate different payroll results.</NOTE><BR><HR ALIGN=CENTER></BLOCKQUOTE></BLOCKQUOTE><BLOCKQUOTE><BLOCKQUOTE><HR ALIGN=CENTER><BR><NOTE><I>Definition: Input</I> is the data that the user enters.</NOTE><BR><HR ALIGN=CENTER></BLOCKQUOTE></BLOCKQUOTE><P>As you can see from the execution of this program, the program takes the user's input and calculates net pay amounts. Input can come from sources other than the user. Programs might get input from a disk file, a modem connected to the telephone, or from other programs running along with yours. Users do not always see the output, either. Programs often perform calculations and data manipulation and send the output of that processing to disk files or to other computers over modem lines.<BR><P>Figure 1.3 illustrates the program flow from writing the program to generating output, such as the payroll output you see here.<BR><P><B> <A HREF="01vel03.gif">Figure 1.3. The program's instructions produce </B><B>the output.</A></B><BR><BLOCKQUOTE><BLOCKQUOTE><HR ALIGN=CENTER><BR><NOTE><B>Warning: </B>The output you get after typing with a word processor would be the text on paper or on the screen. The output from other programs might be as diverse as payroll reports, calculations, or graphics. The program's instructions determines what the program produces.</NOTE><BR><HR ALIGN=CENTER></BLOCKQUOTE></BLOCKQUOTE><BR><A NAME="E69E16"></A><H4 ALIGN=CENTER><CENTER><FONT SIZE=4 COLOR="#FF0000"><B>Exterminating Bugs Is Not Trivial</B></FONT></CENTER></H4><BR><BLOCKQUOTE><BLOCKQUOTE><HR ALIGN=CENTER><BR><NOTE><I>Syntax</I> is the grammar of a language.</NOTE><BR><HR ALIGN=CENTER></BLOCKQUOTE></BLOCKQUOTE><P>Bugs are as frustrating in computer programs as they are in computer programmer's houses. Rarely will a program that you write work the first time you run it. There are two kinds of errors: <I>Syntax errors</I>—sounds like "sin tax" and is worse in many ways—and <I>logic errors</I>. Since you do not know the Visual Basic programming language yet, this simple phrase demonstrates the two kinds of errors that can appear in your code:<BR><P>There are two errrors in this sentence.<BR><P>What are the two errors? I'll wait...<BR><P>The first error, a syntax error, is easy to spot. errrors is misspelled. The logic error takes more time to find. The logic error is that the entire sentence is logically wrong—there is only <I>one</I> error, the syntax error errrors.<BR><P>When you begin to write programs, this example sentence may come back to haunt you a bit. Syntax errors are easy to catch because Visual Basic catches all of them for you. In other words, if you type Tezt when Visual Basic expects you to type Text, Visual Basic immediately displays an error message box in the center of your screen. Visual Basic is extremely stubborn when it comes to syntax errors because it refuses to execute your program until you remove all the syntax errors in the code.<BR><P>When you make a logic error, however, Visual Basic cannot help you out. For example, if you were writing a payroll calculation routine and accidentally subtracted $50 from everybody's paycheck, Visual Basic has no way of knowing that you should not subtract that amount. If you tell Visual Basic to subtract the amount—using correct syntax, of course—Visual Basic subtracts the amount. Only until your employees beat your door down will you know that a logic error took place.<BR><BLOCKQUOTE><BLOCKQUOTE><HR ALIGN=CENTER><BR><NOTE><B>Tip: </B>Thoroughly test your programs before you distribute them or use them for important work. Run the program using all combinations of input to find and correct as many logic errors as possible.</NOTE><BR><HR ALIGN=CENTER></BLOCKQUOTE></BLOCKQUOTE><BR><A NAME="E69E17"></A><H4 ALIGN=CENTER><CENTER><FONT SIZE=4 COLOR="#FF0000"><B>Graphical User Interfaces Changed Everything</B></FONT></CENTER></H4><BR><BLOCKQUOTE><BLOCKQUOTE><HR ALIGN=CENTER><BR><NOTE><I>Definition: GUI</I> stands for <I>G</I>raphical <I>U</I>ser <I>I</I>nterface.</NOTE><BR><HR ALIGN=CENTER></BLOCKQUOTE></BLOCKQUOTE><P>A challenging programming problem arose when advanced GUI visual environments, such as Microsoft Windows, appeared in the 1980s. GUI environments require more advanced and difficult programming efforts than text-based computing environments. Although users and programmers wanted easier tools, GUI environments demanded more complex programming tools.<BR><BLOCKQUOTE><BLOCKQUOTE><HR ALIGN=CENTER><BR><NOTE><I>Definition: </I>An <I>event</I> can be a Windows mouse click, a key press, a menu selection, or an internal Windows activity.</NOTE><BR><HR ALIGN=CENTER></BLOCKQUOTE></BLOCKQUOTE><P>It is relatively easy to produce the text-based output shown earlier. It is much more difficult to produce Windows-like screens such as the one shown in Figure 1.4. The user does not have to enter the ID, hours worked, and amounts in any preset order. Neither does the user have to press the three command buttons at the right of the screen in any order. In Windows programs, a specific event determines the next course of action. A Windows program is called an event-driven<I> </I>program as opposed to a text-based procedural program. In Windows, the user determines what happens next by triggering an event to which the Visual Basic program responds.<BR><P><B> <A HREF="01vel04.gif">Figure 1.4. Users randomly control event-driven </B><B>programs.</A></B><BR><P><FONT COLOR="#FF8000"><B><I>Review: </I></B></FONT>Computer programming has progressed a long way from the wiring panels of the early days. Once keyboards were added, what programmers could do grew by leaps and bounds. Actually, it was not until the development of Visual Basic that another great leap in programming tools arrived. The power of programs that you can create with Visual Basic, given the simplicity of Visual Basic's environment, produces as much computer programming advantage today as the keyboard provided over the switch panel. As Yogi Berra once said, "It ain't bragging if it's true!"<BR><BR><A NAME="E68E10"></A><H3 ALIGN=CENTER><CENTER><FONT SIZE=5 COLOR="#FF0000"><B>From BASIC to Visual Basic</B></FONT></CENTER></H3><BR><P><FONT COLOR="#FF8000"><B><I>Concept: </I></B></FONT>As Windows programming tools are developed, their complexity seems to increase. The Microsoft Windows environment requires much more complicated programming efforts than DOS-based non-Windows programs require. Visual Basic bucks the trend by providing a simple approach to writing Windows programs while retaining all the beginning and advanced programming language instructions found in QBasic.<BR><BLOCKQUOTE><BLOCKQUOTE><HR ALIGN=CENTER><BR><NOTE><I>Definition: </I>Text-based programs are often called <I>procedural programs</I>.</NOTE><BR><HR ALIGN=CENTER></BLOCKQUOTE></BLOCKQUOTE><P>Procedural languages such as FORTRAN and QBasic simply don't work well for a GUI environment. The problem—actually, the primary advantage for users—of GUIs is the event-driven processing explained in the previous section. The user does not always do the same thing in the same order. That is, a user might want to select from a pull-down menu, click a mouse button, type text, or compute a mathematical answer, and he might do those tasks in virtually any order. Text-based procedural programming languages essentially required that the program dictate the order of the user's actions. Windows requires a different approach. The traditional programming languages cannot handle the GUI approach well at all.<BR><P>It is possible to write event-driven programs in procedural languages. The majority of Windows programs in use today were written in the C language, a procedural language more similar in style to FORTRAN than
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -