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.

EXAMPLE 7<br />

The following program produces essentially the first two columns of the table in Example 5 of Section<br />

2.5. However, Format is used to right-justify the expense categories <strong>and</strong> to align the numbers.<br />

Object Property Setting<br />

frmExpenses Caption Public 2-year College Expenses<br />

cmdDisplay Caption Display Expenses<br />

picTable Font.Name Courier<br />

Private Sub cmdDisplay_Click()<br />

Dim fmt1 As String, fmt2 As String<br />

Dim col1 As String, col2 As String<br />

‘Average expenses of commuter students (1995-96)<br />

picTable.Cls<br />

picTable.Print Tab(19); “Pb 2-yr”<br />

picTable.Print<br />

fmt1 = “@@@@@@@@@@@@@@@@@” ‘17 @ symbols<br />

fmt2 = “@@@@@@” ‘6 @ symbols<br />

col1 = Format(“Tuition & Fees”, fmt1)<br />

col2 = FormatNumber(1387, 0)<br />

col2 = Format(col2, fmt2)<br />

picTable.Print col1; Tab(19); col2<br />

col1 = Format(“Books & Supplies”, fmt1)<br />

col2 = FormatNumber(577, 0)<br />

col2 = Format(col2, fmt2)<br />

picTable.Print col1; Tab(19); col2<br />

col1 = Format(“Board”, fmt1)<br />

col2 = FormatNumber(1752, 0)<br />

col2 = Format(col2, fmt2)<br />

picTable.Print col1; Tab(19); col2<br />

col1 = Format(“Transportation”, fmt1)<br />

col2 = FormatNumber(894, 0)<br />

col2 = Format(col2, fmt2)<br />

picTable.Print col1; Tab(19); col2<br />

col1 = Format(“Other Expenses”, fmt1)<br />

col2 = FormatNumber(1142, 0)<br />

col2 = Format(col2, fmt2)<br />

picTable.Print col1; Tab(19); col2<br />

picTable.Print Tab(19); “———”<br />

col1 = Format(“Total”, fmt1)<br />

col2 = FormatNumber(5752, 0)<br />

col2 = Format(col2, fmt2)<br />

picTable.Print col1; Tab(19);<br />

col2<br />

End Sub<br />

[Run, <strong>and</strong> then click the comm<strong>and</strong> button.]<br />

Tuition & Fees<br />

Pb 2-Yr<br />

1,387<br />

Books & Supplies 577<br />

Board 1,752<br />

Transportation 894<br />

Other Expenses 1,142<br />

-----<br />

Total 5,752<br />

Built-In Functions 63

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

Saved successfully!

Ooh no, something went wrong!