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.

txtCell(Indx(10, 1)).Text = “Food”<br />

txtCell(Indx(11, 1)).Text = “Rent”<br />

txtCell(Indx(12, 1)).Text = “Books”<br />

txtCell(Indx(13, 1)).Text = “Misc”<br />

End Sub<br />

Private Sub SetStructure()<br />

txtCell(Indx(1, 2)).Text = “Fall”<br />

txtCell(Indx(1, 3)).Text = “Winter”<br />

txtCell(Indx(1, 4)).Text = “Spring”<br />

txtCell(Indx(1, 5)).Text = “Summer”<br />

txtCell(Indx(1, 6)).Text = “Total”<br />

txtCell(Indx(1, 6)).ForeColor = vbGreen<br />

txtCell(Indx(2, 1)).Text = “Income”<br />

txtCell(Indx(2, 1)).ForeColor = vbMagenta<br />

txtCell(Indx(6, 1)).Text = “Total”<br />

txtCell(Indx(6, 1)).ForeColor = vbGreen<br />

txtCell(Indx(8, 1)).Text = “Expenses”<br />

txtCell(Indx(8, 1)).ForeColor = vbMagenta<br />

txtCell(Indx(14, 1)).Text = “Total”<br />

txtCell(Indx(14, 1)).ForeColor = vbGreen<br />

txtCell(Indx(16, 1)).Text = “Balance”<br />

txtCell(Indx(16, 1)).ForeColor = vbGreen<br />

incStartRow = 3<br />

incStopRow = 5<br />

incTotRow = 6<br />

expStartRow = 9<br />

expStopRow = 13<br />

expTotRow = 14<br />

balRow = 16<br />

startCol = 2<br />

stopCol = 5<br />

totCol = 6<br />

End Sub<br />

A Case Study: Calculating with a Spreadsheet 207<br />

Private Sub ShowBalances(itot() As Single, etot() As Single)<br />

Dim col As Integer<br />

For col = startCol To stopCol<br />

txtCell(Indx(balRow, col)).Text = FormatNumber(itot(col) - etot(col), 0)<br />

Next col<br />

End Sub<br />

Private Sub ShowGr<strong>and</strong>Totals(itot() As Single, etot() As Single)<br />

Dim col As Integer, iTotal As Single, eTotal As Single<br />

‘Compute <strong>and</strong> display gr<strong>and</strong> totals for income, expenses, <strong>and</strong> balance<br />

iTotal = 0<br />

eTotal = 0<br />

For col = startCol<br />

To stopCol<br />

iTotal = iTotal + itot(col)<br />

eTotal = eTotal + etot(col)<br />

Next col<br />

txtCell(Indx(incTotRow, totCol)) = FormatNumber(iTotal, 0)<br />

txtCell(Indx(expTotRow, totCol)) = FormatNumber(eTotal, 0)<br />

txtCell(Indx(balRow, totCol)) = FormatNumber(iTotal - eTotal, 0)<br />

End Sub

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

Saved successfully!

Ooh no, something went wrong!