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.

■ THE DESIGN OF THE PROGRAM<br />

Figure 6-9 contains an example of a spreadsheet used to analyze a student’s financial projections<br />

for the four quarters of a year. Column F holds the sum of the entries in columns B<br />

through E, rows 6 <strong>and</strong> 14 hold sums of the entries in rows 3 through 5 <strong>and</strong> 9 through 13, respectively,<br />

<strong>and</strong> row 16 holds the differences of the entries in rows 6 <strong>and</strong> 14. Because the total<br />

balance is negative, some of the amounts in the spreadsheet must be changed <strong>and</strong> the totals <strong>and</strong><br />

balances recalculated.<br />

A B C D E F<br />

1 Fall Winter Spring Summer Total<br />

2 Income<br />

3 Job 1000 1300 1000 2000 5300<br />

4 Parents 200 200 200 0 600<br />

5 Scholarship 150 150 150 0 450<br />

6 Total 1350 1650 1350 2000 6350<br />

7<br />

8 Expenses<br />

9 Tuition 400 0 400 0 800<br />

10 Food 650 650 650 650 2600<br />

11 Rent 600 600 600 400 2200<br />

12 Books 110 0 120 0 230<br />

13 Misc 230 210 300 120 860<br />

14 Total 1990 1460 2070 1170 6690<br />

15<br />

16 Balance –640 190 –720 830 –340<br />

FIGURE 6-9 Spreadsheet for Student’s Financial Projections<br />

The 96 locations in the spreadsheet that hold information are called cells. Each cell is<br />

identified by its row number <strong>and</strong> column letter. For instance, cell 14, C contains the amount<br />

1460. For programming purposes, each column is identified by a number, starting with 1 for<br />

the leftmost column. Thus cell 14, C will be cell 14, 3 in our program.<br />

This case study develops a program to produce a spreadsheet with the five columns of<br />

numbers shown in Figure 6-11, three user-specified categories of income, <strong>and</strong> five user-specified<br />

categories of expenses. The following tasks are to be selected by comm<strong>and</strong> buttons:<br />

1. Start a new spreadsheet. All current category names <strong>and</strong> values are erased <strong>and</strong><br />

the cursor is placed in the text box of the first income category.<br />

2. Quit.<br />

Three additional tasks need to be performed as the result of other events:<br />

1. Create the spreadsheet when the form is loaded.<br />

2. Limit the user to editing category names <strong>and</strong> quarterly values.<br />

3. Display totals after a change is made in the spreadsheet.<br />

■ THE USER INTERFACE<br />

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

Each cell in the spreadsheet will be an element of a text box control array. A control array of<br />

labels is needed for the numeric labels to the left of each row <strong>and</strong> another control array of labels<br />

for the alphabetic labels at the top of each column. Finally, two comm<strong>and</strong> buttons are required.<br />

The task of controlling which cells the user can edit will be h<strong>and</strong>led by a GotFocus<br />

event. The task of updating the totals will be h<strong>and</strong>led by a LostFocus event. Figure 6-10 shows<br />

one possible form design with all control elements loaded. For this application of a spreadsheet,<br />

the headings that have been assigned to cells in rows 1, 2, 6, 8, 14, <strong>and</strong> 16 are fixed; the user<br />

will not be allowed to edit them. The other entries in column A, the category names, may be<br />

edited by the user, but we have provided the set from Figure 6-9 as the default.

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

Saved successfully!

Ooh no, something went wrong!