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.

58 <strong>Computer</strong> <strong>Programming</strong> <strong>Concepts</strong> <strong>and</strong> <strong>Visual</strong> <strong>Basic</strong><br />

6. If all the data in a file have been read by Input # statements <strong>and</strong> another item is<br />

requested by an Input # statement, a box will appear displaying the message<br />

“Input past end of file.”<br />

7. Numeric data in a text box, input box, or file must be a constant. It cannot be a<br />

variable or an expression. For instance, num, 1 / 2, <strong>and</strong> 2 + 3 are not acceptable.<br />

8. To skip a Print zone, just include two consecutive commas.<br />

9. Print zones are usually employed to align information into columns. Since most<br />

fonts have proportionally-spaced characters, wide characters occupy more than<br />

one fixed-width column <strong>and</strong> narrow characters occupy less. The best <strong>and</strong> most<br />

predictable results are obtained when a fixed-pitch font (such as Courier) is<br />

used with print zones.<br />

10. The Tab function cannot be used to move the cursor to the left. If the position<br />

specified in a Tab function is to the left of the current cursor position, the cursor<br />

will move to that position on the next line. For instance, the line<br />

picBox.Print “hello”; Tab(3); “good-bye”<br />

results in the output<br />

hello<br />

good-bye<br />

11. The statement Close, without any reference number, closes all open files.<br />

12. Windows allows you to alternate between <strong>Visual</strong> <strong>Basic</strong> <strong>and</strong> Notepad without<br />

exiting either application. To invoke Notepad with Windows, click on the Start<br />

button; successively select Programs, Accessories, <strong>and</strong> Notepad; <strong>and</strong> then click<br />

on Notepad or press the Enter key. Now that both <strong>Visual</strong> <strong>Basic</strong> <strong>and</strong> Notepad<br />

have been invoked, you can go from one application to the other by holding<br />

down the Alt key <strong>and</strong> repeatedly pressing the Tab key until the name of the other<br />

application appears. When the Alt key is released, the named application<br />

becomes active.<br />

2.6 BUILT-IN FUNCTIONS<br />

<strong>Visual</strong> <strong>Basic</strong> has a number of built-in functions that greatly extend its capability. These functions<br />

perform such varied tasks as taking the square root of a number, counting the number of<br />

characters in a string, <strong>and</strong> capitalizing letters. Functions associate with one or more values,<br />

called the input, a single value, called the output. The function is said to return the output value.<br />

The three functions considered in what follows have numeric input <strong>and</strong> output.<br />

■ NUMERIC FUNCTIONS: SQR, INT, ROUND<br />

The function Sqr calculates the square root of a number. The function Int finds the greatest integer<br />

less than or equal to a number. Therefore, Int discards the decimal part of positive numbers.<br />

The value of Round (n, r) is the number n rounded to r decimal places. The parameter r<br />

can be omitted. If so, n is rounded to a whole number. Some examples follow:<br />

Sqr(9) is 3. Int(2.7) is 2. Round(2.7) is 3.<br />

Sqr(0) is 0. Int(3) is 3. Round(2.317, 2) is 2.32.<br />

Sqr(2) is 1.414214. Int(-2.7) is -3. Round(2.317, 1) is 2.3.<br />

The terms inside the parentheses can be either numbers (as shown), numeric variables, or numeric<br />

expressions. Expressions are first evaluated to produce the input.

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

Saved successfully!

Ooh no, something went wrong!