19.12.2012 Views

Computer Programming Concepts and Visual Basic David I. Schneider

Computer Programming Concepts and Visual Basic David I. Schneider

Computer Programming Concepts and Visual Basic David I. Schneider

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

to the file by the filespec “C:\DATA.TXT” produces the run-time error “File<br />

not found.”<br />

The dialog box generated by a run-time error states the type of error <strong>and</strong> has a<br />

row of four comm<strong>and</strong> buttons captioned Continue, End, Debug, <strong>and</strong> Help. If<br />

you click on the Debug comm<strong>and</strong> button, <strong>Visual</strong> <strong>Basic</strong> will highlight in yellow<br />

the line of code that caused the error. (Note: After a run-time error occurs, the<br />

program is said to be in break mode. See the first page of Appendix D for a discussion<br />

of the three program modes.)<br />

7. A third type of error is the so-called logical error. Such an error occurs when<br />

a program does not perform the way it was intended. For instance, the line<br />

ave = firstNum + secondNum / 2<br />

is syntactically correct. However, the missing parentheses in the first line are<br />

responsible for an incorrect value being generated. Appendix D discusses<br />

debugging tools that can be used to detect <strong>and</strong> correct logical errors.<br />

8. The omission of the asterisk to denote multiplication is a common error. For<br />

instance, the expression a(b + c) is not valid. It should read a * (b + c).<br />

9. The largest number that most of the numeric variables considered in this text<br />

can represent is 3.402823E+38. Attempting to generate larger values produces<br />

the message “Overflow.” The numbers generated by the programs in this text<br />

usually have a maximum of seven digits.<br />

10. A Review of Exponents. The expression 23 means 2 � 2 � 2, the product of three<br />

2’s. The number 3 is called the exponent, <strong>and</strong> the number 2 is called the base.<br />

In general, if r is a positive integer <strong>and</strong> a is a number, then a is defined as follows:<br />

a r = a � a. . . a<br />

r factors<br />

The process of calculating a r is called raising a to the rth power. Some other<br />

types of exponents are the following:<br />

a 1 / 2 = �a� 9 1\2 = 3<br />

a 1/n = n �a� n positive integer 16 1/4 = 2<br />

a m/n = ( n �a�) m m, n positive integers 8 2/3 = ( 3 �8�) 2 = 4<br />

a –r = 1/a r a ≠ 0 10– 2 = .01<br />

11. More than one statement can be placed on a single line of a program provided<br />

the statements are separated by colons. For instance, the code inside the event<br />

procedure in Example 3 can be written as<br />

picResults.Cls: a = 5: b = 4: picResults.Print a * (2 + b)<br />

In general, though, programs are much easier to follow if just one statement<br />

appears on each line. In this text, we almost always use single-statement lines.<br />

12. When you first open a program that has been saved on disk, the Code window<br />

may not appear. If so, run <strong>and</strong> then terminate the program to see the Code window.<br />

To see the Form window, click on Object in the View menu or press<br />

Shift+F7. To return to the Code window, click on Code in the View window or<br />

press F7.<br />

Numbers 41

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!