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.

4. The items in the value list must evaluate to a constant of the same type, string<br />

or numeric, as the selector. For instance, if the selector evaluates to a string<br />

value, as in<br />

Dim firstName A String<br />

firstName = txtBox.Text<br />

Select Case first Name<br />

then the clause<br />

Case Len(firstNme)<br />

would be meaningless.<br />

5. If the word Is, which should precede an inequality sign in a value list, is accidentally<br />

omitted, the smart editor will automatically insert it when checking the line.<br />

6. A Case clause of the form Case b To c selects values from b to c inclusive. However,<br />

the extreme values can be excluded by placing the action inside an If block<br />

beginning with If (selector b) And (selector c) Then.<br />

7. The value of b must be less than or equal to the value of c in a Case clause of<br />

the form Case b To c.<br />

8. Every Select Case block can be replaced by an If block. Select Case is preferable<br />

to an If block when the possible choices have more or less the same importance.<br />

9. In Appendix D, the section “Stepping Through Programs Containing Selection<br />

Structures: Section 4” uses the <strong>Visual</strong> <strong>Basic</strong> debugging tools to trace the flow<br />

through a Select Case block.<br />

4.4 A CASE STUDY: WEEKLY PAYROLL<br />

This case study processes a weekly payroll using the 1998 Employer’s Tax Guide. Table 4.2<br />

shows typical data used by a company’s payroll office. These data are processed to produce<br />

the information in Table 4.3 that is supplied to each employee along with his or her paycheck.<br />

The program should request the data from Table 4.2 for an individual as input <strong>and</strong> produce output<br />

similar to that in Table 4.3.<br />

The items in Table 4.3 should be calculated as follows:<br />

Current Earnings: Hourly wage times hours worked (with time-<strong>and</strong>-a-half after 40 hours)<br />

Year-to-Date Earnings: Previous year-to-date earnings plus current earnings<br />

FICA Tax: Sum of 6.2 percent of first $68,400 of earnings (Social Security benefits tax) <strong>and</strong><br />

1.45 percent of total wages (Medicare tax)<br />

Federal Income Tax Withheld: Subtract $51.92 from the current earnings for each withholding<br />

exemption <strong>and</strong> use Table 4.4 or Table 4.5, depending on marital status<br />

Check Amount: [Current earnings] – [FICA taxes] – [Income tax withheld]<br />

TABLE 4.2<br />

Employee Data<br />

A Case Study: Weekly Payroll 119<br />

Previous<br />

Hourly Hours Withholding Marital Year-to-Date<br />

Name Wage Worked Exemptions Status Earnings<br />

Al Clark $45.50 38 4 Married $68,925.50<br />

Ann Miller $44.00 35 3 Married $68,200.00<br />

John Smith $17.95 50 1 Single $30,604.75<br />

Sue Taylor $25.50 43 2 Single $36,295.50

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

Saved successfully!

Ooh no, something went wrong!