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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

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

sends expr to the printer in exactly the same way picBox.Print sends output to a picture box.<br />

You can use semicolons, commas for print zones, <strong>and</strong> Tab.<br />

Font properties can be set with statements like<br />

Printer.Font.Name = “Script”<br />

Printer.Font.Bold = True<br />

Printer.Font.Size = 12<br />

Another useful printer comm<strong>and</strong> is<br />

Printer.NewPage<br />

which starts a new page.<br />

Windows’ print manager usually waits until an entire page has been completed before<br />

starting to print. To avoid losing information, execute the statement<br />

Printer.EndDoc<br />

when you are finished printing.<br />

The statement<br />

PrintForm<br />

prints the content of the form.<br />

■ INTERNAL DOCUMENTATION<br />

Now that we have the capability to write more complicated programs, we must concern ourselves<br />

with program documentation. Program documentation is the inclusion of comments<br />

that specify the intent of the program, the purpose of the variables, the nature of the data in<br />

the files, <strong>and</strong> the tasks performed by individual portions of the program. To create a comment<br />

line, just begin the line with an apostrophe. Such a line is completely ignored when the program<br />

is executed. (The keyword Rem can be used instead of an apostrophe. Rem is an abbreviation<br />

of Remark.) Program documentation appears whenever the program is displayed or<br />

printed. Also, a line of code can be documented by adding an apostrophe, followed by the desired<br />

information, to the end of the line. Comments (also known as Rem statements) appear<br />

green on the screen.<br />

EXAMPLE 7<br />

Document the program in Example 2.<br />

SOLUTION<br />

In the following program, the first comment describes the entire program, the next three comments give<br />

the meanings of the variables, <strong>and</strong> the final comment describes the items in each line of the file.<br />

Private Sub cmdCompute_Click()<br />

‘Compute weekly pay<br />

Dim nom As String ‘Employee name<br />

Dim wage As Single ‘Hourly pay<br />

Dim hrs As Single ‘Number of hours worked during week<br />

picPay.Cls<br />

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

‘Get person’s name, hourly pay, <strong>and</strong> hours worked<br />

Input #1, nom, wage, hrs<br />

picPay.Print nom; hrs * wage Input #1, nom, wage,<br />

hrs picPay.Print nom; hrs * wage<br />

Close #1<br />

End Sub

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

Saved successfully!

Ooh no, something went wrong!