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.

Some of the benefits of documentation are as follows:<br />

1. Other people can easily comprehend the program.<br />

2. The program can be understood when read later.<br />

3. Long programs are easier to read because the purposes of individual pieces can<br />

be determined at a glance.<br />

COMMENTS<br />

1. <strong>Visual</strong> <strong>Basic</strong> provides a convenient device for accessing a file that resides in the<br />

same folder as the (saved) program. After a program has been saved in a folder,<br />

the value of App.Path is the string containing the name of the folder. Therefore,<br />

if a program contains a line such as<br />

Open App.Path & “\DATA.TXT” For Input As #1<br />

<strong>Visual</strong> <strong>Basic</strong> will look for the file DATA.TXT in the folder containing the program.<br />

The programs from this book, as well as the data files they use, all are contained<br />

in the folder Programs on the CD accompanying this book. On the CD,<br />

App.Path is used in every Open statement. Therefore, even after you copy the<br />

contents of the Programs folder onto a hard drive or diskette, the programs will<br />

continue to execute properly without your having to alter any paths.<br />

2. The text box <strong>and</strong> input box provide a whole new dimension to the capabilities<br />

of a program. The user, rather than the programmer, can provide the data to be<br />

processed.<br />

3. A string used in a file does not have to be enclosed by quotation marks. The<br />

only exceptions are strings containing commas or leading <strong>and</strong> trailing spaces.<br />

4. If an Input # statement looks for a string <strong>and</strong> finds a number, it will treat the<br />

number as a string. Suppose the first two entries in the file DATA.TXT are the<br />

numbers 2 <strong>and</strong> 3.<br />

Private Sub cmdButton_Click()<br />

Dim a As String, b As String<br />

picBox.Cls<br />

Open “DATA.TXT” For Input As #1<br />

Input #1, a, b<br />

picBox.Print a + b<br />

Close #1<br />

End Sub<br />

[Run <strong>and</strong> then click the comm<strong>and</strong> button. The following is displayed in the picture<br />

box.]<br />

23<br />

5. If an Input # statement looks for a number <strong>and</strong> finds a string, the Input # statement<br />

will assign the value 0 to the numeric variable. For instance, suppose the<br />

first two entries in the file DATA.TXT are “ten” <strong>and</strong> 10. Then after the statement<br />

Input #1, num1, num2<br />

is executed, where um1 <strong>and</strong> num2 are numeric variables, the values of these<br />

variables will be 0 <strong>and</strong> 10.<br />

Input <strong>and</strong> Output 57

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

Saved successfully!

Ooh no, something went wrong!