Example Application: Payroll Evaluation - 1 Week
Example Application: Payroll Evaluation - 1 Week
Description
We are learnin how to program in the Visual Basic programming language. We will create a Windows Forms (WinForms) graphical application that contains Windows controls for a time sheet. The user will provide the necessary values and we will use them to make the necessary calculations. Then we will display a pay summary.
Practical Learning: Creating the Application

| Control | Name | Text | Other Properties | |
| GroupBox | Employee Identification | |||
| Label | &Employee Name: | |||
| TextBox | TxtEmployeeName | AutoCompleteCustomSource Andy Barang Thomas Mallone Gertrude Monay Christophe Yuen Micheline Hammond Paul Bertrand Yamaguchi AutoCompleteMode: Suggest AutoCompleteSource: CustomSource |
||
| Label | Hourly &Salary: | |||
| TextBox | TxtHourlySalary | |||
| GroupBox | Time Values | |||
| Label | Monday | |||
| Label | Tuesday | |||
| Label | Wednesday | |||
| Label | Thursday | |||
| Label | Friday | |||
| Label | Saturday | |||
| Label | Sunday | |||
| Label | Work Week: | |||
| TextBox | TxtMonday | TextAlign: Right | ||
| TextBox | TxtTuesday | TextAlign: Right | ||
| TextBox | TxtWednesday | TextAlign: Right | ||
| TextBox | TxtThursday | TextAlign: Right | ||
| TextBox | TxtFriday | TextAlign: Right | ||
| TextBox | TxtSaturday | TextAlign: Right | ||
| TextBox | TxtSunday | TextAlign: Right | ||
| GroupBox | Calculation | |||
| Label | Time | |||
| Label | Pay Amt | |||
| Label | btnCalculate | Calculate | ||
| Label | Regular | |||
| TextBox | TxtRegularTime | TextAlign: Right Enabled: False |
||
| TextBox | TxtRegularPay | TextAlign: Right Enabled: False |
||
| Label | Net Pay: | |||
| TextBox | TxtNetPay | TextAlign: Right Enabled: False |
||
| Label | Overtime | |||
| TextBox | TxtOvertime | TextAlign: Right Enabled: False |
||
| TextBox | TxtOvertimeAmount | TextAlign: Right Enabled: False |
||
| Label | btnClose | AutoSize: False | ||
Public Class Exercise
Private Sub BtnCalculateClick(sender As Object, e As EventArgs) Handles BtnCalculate.Click
Dim Monday As Double
Dim Tuesday As Double
Dim Wednesday As Double
Dim Thursday As Double
Dim Friday As Double
Dim Saturday As Double
Dim Sunday As Double
Dim TotalTime As Double
Dim RegularTime As Double
Dim OverTime As Double
Dim RegularPay As Double
Dim OvertimePay 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
Monday = CDbl(TxtMonday.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)
TxtMonday.Focus()
End Try
Try
Tuesday = CDbl(TxtTuesday.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)
TxtTuesday.Focus()
End Try
Try
Wednesday = CDbl(TxtWednesday.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)
TxtWednesday.Focus()
End Try
Try
Thursday = CDbl(TxtThursday.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)
TxtThursday.Focus()
End Try
Try
Friday = CDbl(TxtFriday.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)
TxtFriday.Focus()
End Try
Try
Saturday = CDbl(TxtSaturday.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)
TxtSaturday.Focus()
End Try
Try
Sunday = CDbl(TxtSunday.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)
TxtSunday.Focus()
End Try
REM Calculate the total number of hours for each week
TotalTime = Monday + Tuesday + Wednesday +
Thursday + Friday + Saturday + Sunday
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 TotalTime < 40 Then
RegularTime = TotalTime
RegularPay = HourlySalary * RegularTime
OverTime = 0.00
OvertimePay = 0.00
REM If the employee worked over 40 hours, calculate the overtime
ElseIf TotalTime >= 40 Then
RegularTime = 40
RegularPay = HourlySalary * 40
OverTime = TotalTime - 40
OvertimePay = OverTime * OvertimeSalary
End If
Dim NetPay As Double = 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 ClassPrivate Sub BtnCloseClick(sender As Object, e As EventArgs) Handles BtnClose.Click
End
End Sub
Employee Name: Gertrude Monay
Hourly Salary: 28.46
Work Week
Monday: 8
Tuesday: 7.5
Wednesday: 6
Thursday: 7.5
Friday: 6.5
Saturday: 0
Sunday: 0


Employee Name: Thomas Mallone
Hourly Salary: 31.68
Work Week
Monday: 8
Tuesday: 10.5
Wednesday: 9
Thursday: 8
Friday: 8
Saturday: 0
Sunday: 0
|
|
|||
| Home | Copyright © 2010-2026, FunctionX | Monday 23 March 2026, 17:59 | Home |
|
|
|||