Example Application: Payroll Evaluation
Example Application: Payroll Evaluation
Description
This application evaluates payroll, using the total time worked in one or two weeks by an employee and his or her hourly salary. The calculation takes overtime into account.
Practical Learning: Creating the Application
Control | Name | Text | Other Properties | |
GroupBox | Employee Identification | |||
Label | &Employee Name: | |||
TextBox | TxtEmployeeName | AutoCompleteCustomSource Andy Barang Thomas Stones Gertrude Monay Christophe Yuen Micheline Hammond Paul Bertrand Yamaguchi AutoCompleteSource: Suggest AutoCompleteMode: CustomSource |
||
Label | Hourly &Salary: | |||
TextBox | TxtHourlySalary | |||
GroupBox | Time Values | |||
Label | Monday | |||
Label | Tuesday | |||
Label | Wednesday | |||
Label | Thursday | |||
Label | Friday | |||
Label | Saturday | |||
Label | Sunday | |||
Label | First Week: | |||
TextBox | TxtMonday1 | 0.00 | TextAlign: Right | |
TextBox | TxtTuesday1 | 0.00 | TextAlign: Right | |
TextBox | TxtWednesday1 | 0.00 | TextAlign: Right | |
TextBox | TxtThursday1 | 0.00 | TextAlign: Right | |
TextBox | TxtFriday1 | 0.00 | TextAlign: Right | |
TextBox | TxtSaturday1 | 0.00 | TextAlign: Right | |
TextBox | TxtSunday1 | 0.00 | TextAlign: Right | |
Label | Second Week: | |||
TextBox | TxtMonday2 | 0.00 | TextAlign: Right | |
TextBox | TxtTuesday2 | 0.00 | TextAlign: Right | |
TextBox | TxtWednesday2 | 0.00 | TextAlign: Right | |
TextBox | TxtThursday2 | 0.00 | TextAlign: Right | |
TextBox | TxtFriday2 | 0.00 | TextAlign: Right | |
TextBox | TxtSaturday2 | 0.00 | TextAlign: Right | |
TextBox | TxtSunday2 | 0.00 | TextAlign: Right | |
GroupBox | Payroll Processing | |||
Label | Hours | |||
Label | Amount | |||
Label | btnCalculate | Calculate | ||
Label | Regular | |||
TextBox | TxtRegularTime | 0.00 | TextAlign: Right Enabled: False |
|
TextBox | TxtRegularAmount | 0.00 | TextAlign: Right Enabled: False |
|
Label | Net Pay: | |||
TextBox | TxtNetPay | 0.00 | TextAlign: Right Enabled: False |
|
Label | Overtime | |||
TextBox | TxtOvertime | 0.00 | TextAlign: Right Enabled: False |
|
TextBox | TxtOvertimeAmount | 0.00 | TextAlign: Right Enabled: False |
|
Label | btnClose | AutoSize: False |
Public Class Exercise Private Sub BtnCalculateClick(sender As Object, e As EventArgs) Handles BtnCalculate.Click Dim Week1Monday As Double Dim Week1Tuesday As Double Dim Week1Wednesday As Double Dim Week1Thursday As Double Dim Week1Friday As Double Dim Week1Saturday As Double Dim Week1Sunday As Double Dim Week2Monday As Double Dim Week2Ttuesday As Double Dim Week2Wednesday As Double Dim Week2Thursday As Double Dim Week2Friday As Double Dim Week2Saturday As Double Dim Week2Sunday As Double Dim HourlySalary As Double REM Get the hourly salary. Use exception handling in case the user types a bad value. Try HourlySalary = CDbl(TxtHourlySalary.Text) Catch fe As FormatException MsgBox("The value you typed for the salary is invalid. " & "Please try again.", "Payroll Evaluation", MsgBoxStyle.OkOnly Or MsgBoxStyle.Information) TxtHourlySalary.Focus() End Try REM Get the value for each work dayworked. REM Use exception handling for each text box in case the user types a bad value. Try Week1Monday = CDbl(TxtWeek1Monday.Text) Catch fe As FormatException MsgBox("You typed an invalid value for Monday of the first week. " & "Please try again.", "Payroll Evaluation", MsgBoxStyle.OkOnly Or MsgBoxStyle.Information) TxtWeek1Monday.Focus() End Try Try Week1Tuesday = CDbl(TxtWeek1Tuesday.Text) Catch fe As FormatException MsgBox("You typed an invalid value for Tuesday of the first week. " & "Please try again.", "Payroll Evaluation", MsgBoxStyle.OkOnly Or MsgBoxStyle.Information) TxtWeek1Tuesday.Focus() End Try Try Week1Wednesday = CDbl(TxtWeek1Wednesday.Text) Catch fe As FormatException MsgBox("You typed an invalid value for Wednesday of the first week. " & "Please try again.", "Payroll Evaluation", MsgBoxStyle.OkOnly Or MsgBoxStyle.Information) TxtWeek1Wednesday.Focus() End Try Try Week1Thursday = CDbl(TxtWeek1Thursday.Text) Catch fe As FormatException MsgBox("You typed an invalid value for Thursday of the first week. " & "Please try again.", "Payroll Evaluation", MsgBoxStyle.OkOnly Or MsgBoxStyle.Information) TxtWeek1Thursday.Focus() End Try Try Week1Friday = CDbl(TxtWeek1Friday.Text) Catch fe As FormatException MsgBox("You typed an invalid value for Firday of the first week. " & "Please try again.", "Payroll Evaluation", MsgBoxStyle.OkOnly Or MsgBoxStyle.Information) TxtWeek1Friday.Focus() End Try Try Week1Saturday = CDbl(TxtWeek1Saturday.Text) Catch ex As Exception MsgBox("You typed an invalid value for Saturday of the first week. " & "Please try again.", "Payroll Evaluation", MsgBoxStyle.OkOnly Or MsgBoxStyle.Information) TxtWeek1Saturday.Focus() End Try Try Week1Sunday = CDbl(TxtWeek1Sunday.Text) Catch fe As FormatException MsgBox("You typed an invalid value for Sunday of the first week. " & "Please try again.", "Payroll Evaluation", MsgBoxStyle.OkOnly Or MsgBoxStyle.Information) TxtWeek1Sunday.Focus() End Try Try Week2Monday = CDbl(TxtWeek2Monday.Text) Catch fe As FormatException MsgBox("You typed an invalid value for Monday of the second week. " & "Please try again.", "Payroll Evaluation", MsgBoxStyle.OkOnly Or MsgBoxStyle.Information) TxtWeek2Monday.Focus() End Try Try Week2Ttuesday = CDbl(TxtWeek2Tuesday.Text) Catch fe As FormatException MsgBox("You typed an invalid value for Tuesday of the second week. " & "Please try again.", "Payroll Evaluation", MsgBoxStyle.OkOnly Or MsgBoxStyle.Information) TxtWeek2Tuesday.Focus() End Try Try Week2Wednesday = CDbl(TxtWeek2Wednesday.Text) Catch fe As FormatException MsgBox("You typed an invalid value for Wednesday of the second week. " & "Please try again.", "Payroll Evaluation", MsgBoxStyle.OkOnly Or MsgBoxStyle.Information) TxtWeek2Wednesday.Focus() End Try Try Week2Thursday = CDbl(TxtWeek2Thursday.Text) Catch fe As FormatException MsgBox("You typed an invalid value for Thursday of the second week. " & "Please try again.", "Payroll Evaluation", MsgBoxStyle.OkOnly Or MsgBoxStyle.Information) TxtWeek2Thursday.Focus() End Try Try Week2Friday = CDbl(TxtWeek2Friday.Text) Catch fe As FormatException MsgBox("You typed an invalid value for Friday of the second week. " & "Please try again.", "Payroll Evaluation", MsgBoxStyle.OkOnly Or MsgBoxStyle.Information) TxtWeek2Friday.Focus() End Try Try Week2Saturday = CDbl(TxtWeek2Saturday.Text) Catch fe As FormatException MsgBox("You typed an invalid value for Saturday of the second week. " & "Please try again.", "Payroll Evaluation", MsgBoxStyle.OkOnly Or MsgBoxStyle.Information) TxtWeek2Saturday.Focus() End Try Try Week2Sunday = CDbl(TxtWeek2Sunday.Text) Catch fe As FormatException MsgBox("You typed an invalid value for Sunday of the second week. " & "Please try again.", "Payroll Evaluation", MsgBoxStyle.OkOnly Or MsgBoxStyle.Information) TxtWeek2Sunday.Focus() End Try Dim Week1RegularTime As Double Dim Week2RegularTime As Double Dim Week1OverTime As Double Dim Week2OverTime As Double Dim Week1RegularPay As Double Dim Week2RegularPay As Double Dim Week1OvertimePay As Double Dim Week2OvertimePay As Double REM Calculate the total number of hours for each week Dim Week1TotalTime = Week1Monday + Week1Tuesday + Week1Wednesday + Week1Thursday + Week1Friday + Week1Saturday + Week1Sunday Dim Week2TotalTime = Week2Monday + Week2Ttuesday + Week2Wednesday + Week2Thursday + Week2Friday + Week2Saturday + Week2Sunday REM The overtime Is paid time And half Dim OvertimeSalary As Double = HourlySalary * 1.5 REM If the employee worked below 40 hours, there Is no overtime If Week1TotalTime < 40 Then Week1RegularTime = Week1TotalTime Week1RegularPay = HourlySalary * Week1RegularTime Week1OverTime = 0.00 Week1OvertimePay = 0.00 REM If the employee worked over 40 hours, calculate the overtime ElseIf Week1TotalTime >= 40 Then Week1RegularTime = 40 Week1RegularPay = HourlySalary * 40 Week1OverTime = Week1TotalTime - 40 Week1OvertimePay = Week1OverTime * OvertimeSalary End If If Week2TotalTime < 40 Then Week2RegularTime = Week2TotalTime Week2RegularPay = HourlySalary * Week2RegularTime Week2OverTime = 0.00 Week2OvertimePay = 0.00 ElseIf Week2TotalTime >= 40 Then Week2RegularTime = 40 Week2RegularPay = HourlySalary * 40 Week2OverTime = Week2TotalTime - 40 Week2OvertimePay = Week2OverTime * OvertimeSalary End If Dim RegularTime = Week1RegularTime + Week2RegularTime Dim OverTime = Week1OverTime + Week2OverTime Dim RegularPay = Week1RegularPay + Week2RegularPay Dim OvertimePay = Week1OvertimePay + Week2OvertimePay Dim NetPay = RegularPay + OvertimePay TxtRegularTime.Text = FormatNumber(RegularTime) TxtOverTime.Text = FormatNumber(OverTime) TxtRegularPay.Text = FormatCurrency(RegularPay) TxtOvertimePay.Text = FormatCurrency(OvertimePay) TxtNetPay.Text = FormatCurrency(NetPay) End Sub End Class
Private Sub BtnCloseClick(sender As Object, e As EventArgs) Handles BtnClose.Click End End Sub
Employee Name: Gertrude Monay Hourly Salary: 28.46 First Week Monday: 8 Tuesday: 7.5 Wednesday: 6 Thursday: 7.5 Friday: 6.5 Saturday: 0 Sunday: 0 Second Week Monday: 7 Tuesday: 8 Wednesday: 6 Thursday: 6 Friday: 8 Saturday: 0 Sunday: 0
Employee Name: Thomas Stones Hourly Salary: 31.68 First Week Monday: 8 Tuesday: 10 Wednesday: 9 Thursday: 8.5 Friday: 8 Saturday: 0 Sunday: 0 Second Week Monday: 9 Tuesday: 8 Wednesday: 10.5 Thursday: 9 Friday: 8.5 Saturday: 0 Sunday: 0
|
|||
Home | Copyright © 2010-2025, FunctionX | Thursday 12 December 2024, 09:34 | Home |
|