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.

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

had the focus, then the GotFocus event procedure would be invoked again as a<br />

result of the SetFocus, <strong>and</strong> then again as a result of the SetFocus performed by<br />

this invocation of GotFocus, <strong>and</strong> so on, resulting in an infinite loop.<br />

3. txtCell_LostFocus invokes the general procedure DisplayTotals when the cursor<br />

leaves one of the spreadsheet cells. DisplayTotals in turn invokes five general procedures<br />

that each compute one set of needed totals <strong>and</strong> display the results by<br />

assigning values to appropriate text boxes. TotalIncome adds up the income for<br />

each quarter <strong>and</strong> saves the results in the array iTot( ). Similarly, TotalExpenses<br />

adds up the expenses for each quarter <strong>and</strong> saves the results in the array eTot( ).<br />

ComputeBalances takes the results stored in iTot( ) <strong>and</strong> eTot( ) <strong>and</strong> subtracts them<br />

to determine the balance for each quarter. TotalRows adds the four quarters for<br />

each category <strong>and</strong> assigns the results to the text boxes at the right end of each row.<br />

Finally, DetermineGr<strong>and</strong>Totals adds the values in iTot( ) <strong>and</strong> eTot( ) to determine<br />

the values for the right end of the “balance” row <strong>and</strong> each “total” row.<br />

4. cmdNew_Click prepares for the entry of a new spreadsheet by setting the Text<br />

property of each element of the control array txtCell( ) to the null string <strong>and</strong><br />

then setting focus to the first cell in the spreadsheet.<br />

5. cmdQuit_Click ends the program.<br />

FIGURE 6.12 Hierarchy Chart for Spreadsheet Program<br />

TABLE 6.8<br />

Tasks <strong>and</strong> Their Procedures<br />

1. Create & Initialize spreadsheet Form_Load<br />

1.1 Create & position cells & labels CreateSpreadsheet<br />

1.2 Display fixed headings SetStructure<br />

1.3 Display default categories SetDefaults<br />

2. Prevent editing of wrong cells txtCell_GotFocus<br />

3. Update totals when cursor leaves a cell txtCell_LostFocus (Display<br />

Totals)<br />

3.1 Total income each quarter TotalIncome<br />

3.2 Total expenses each quarter TotalExpenses<br />

3.3 Compute balances each quarter ShowBalances<br />

3.4 Total each income & expense category TotalRows<br />

3.5 Determine gr<strong>and</strong> totals ShowGr<strong>and</strong>Totals<br />

4. Start a new spreadsheet cmdNew_Click<br />

5. End program cmdQuit_Click

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

Saved successfully!

Ooh no, something went wrong!