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.

‘Program to compute employees’ weekly payroll<br />

Private Sub cmdDisplay_Click()<br />

Dim empName As String ‘Name of employee<br />

Dim hrWage As Single ‘Hourly wage<br />

Dim hrsWorked As Single ‘Hours worked this week<br />

Dim exemptions As Integer ‘Number of exemptions for employee<br />

Dim mStatus As String ‘Marital status: S for Single; M for Married<br />

Dim prevPay As Single ‘Total pay for year excluding this week<br />

Dim pay As Single ‘This week’s pay before taxes<br />

Dim totalPay As Single ‘Total pay for year including this week<br />

Dim ficaTax As Single ‘FICA taxes for this week<br />

Dim fedTax As Single ‘Federal income tax withheld this week<br />

Dim check As Single ‘Paycheck this week (take-home pay)<br />

‘Obtain data, compute payroll, display results<br />

Call InputData(empName, hrWage, hrsWorked, exemptions,<br />

mStatus, prevPay) ‘Task 0<br />

pay = Gross_Pay(hrWage, hrsWorked) ‘Task 1<br />

totalPay = Total_Pay(prevPay, pay) ‘Task 2<br />

ficaTax = FICA_Tax(pay, prevPay, totalPay) ‘Task 3<br />

fedTax = Fed_Tax(pay, exemptions, mStatus) ‘Task 4<br />

check = Net_Check(pay, ficaTax, fedTax) ‘Task 5<br />

Call ShowPayroll(empName, pay, totalPay, ficaTax, fedTax, check)<br />

End Sub<br />

‘Task 6<br />

Private Sub cmdNext_Click()<br />

‘Clear all text boxes for next employee’s data<br />

txtName.Text = “ “<br />

txtWage.Text = “ “<br />

txtHours.Text = “ “<br />

txtExempts.Text = “ “<br />

txtMarital.Text = “ “<br />

txtPriorPay.Text = “ “<br />

picResults.Cls<br />

End Sub<br />

Private Sub cmdQuit_Click()<br />

End<br />

End Sub<br />

Private Function Fed_Tax(pay As Single, exemptions As Integer, mStatus As String)<br />

Dim adjPay As Single<br />

‘Task 4.1: Compute federal income tax<br />

adjPay = pay - (51.92 * exemptions)<br />

If adjPay < 0 Then<br />

adjPay = 0<br />

End If<br />

If mStatus = “S” Then<br />

Fed_Tax = TaxSingle(adjPay) ‘Task 4.2<br />

Else<br />

Fed_Tax = TaxMarried(adjPay) ‘Task 4.3<br />

End If<br />

Fed_Tax = Round(Fed_Tax, 2) ‘Round to nearest cent<br />

End Function<br />

Private Function FICA_Tax(pay As Single, prevPay As Single, totalPay As Single)<br />

A Case Study: Weekly Payroll 123

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

Saved successfully!

Ooh no, something went wrong!