Practical
Learning: Creating the Application |
|
- To start a new application, on the main menu, click File -> New ->
Project (or File -> New Project)
- In the Templates list, click Windows Application and set the name to
PayrollProcessing1
- Click OK
- Design the form as follows:
|
Control |
Name |
Text |
Other Properties |
GroupBox |
|
|
Employee Identification |
|
Label |
|
|
&Employee Name: |
|
TextBox |
|
txtEmployeeName |
|
|
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 |
|
Button |
|
btnCalculate |
Calculate |
|
Label |
|
|
Regular |
|
TextBox |
|
txtRegularTime |
0.00 |
TextAlign: Right |
TextBox |
|
txtRegularAmount |
0.00 |
TextAlign: Right |
Label |
|
|
Net Pay: |
|
TextBox |
|
txtNetPay |
0.00 |
TextAlign: Right |
Label |
|
|
Overtime |
|
TextBox |
|
txtOvertime |
0.00 |
TextAlign: Right |
TextBox |
|
txtOvertimeAmount |
0.00 |
TextAlign: Right |
Button |
|
btnClose |
|
|
|
- Double-click the Close button and implement its Click event as follows:
Private Sub btnCloseClick(ByVal sender As System.Object,
ByVal e As System.EventArgs)
Handles btnClose.Click
End
End Sub
|
- On the form, click the text box at the intersection of Time and Regular
- In the Properties window, double-click ReadOnly to change its value to
True
- Do the same for the following text boxes: txtRegularAmount, txtNetPay,
txtOvertime, and txtOvertimeAmount
- On the form, click the txtEmployeeName text box
- In the Properties window, click AutoCompleteCustomSource and click its
ellipsis button
- In the String Collection Editor, enter the following names:
Micheline Hammond
Paul Bertrand Yamaguchi
Gertrude Monay
Ernestine Ngaleu
Andy Barang
Christophe Yuen
Jean Michel Kankan
- Click OK
- Click AutoCompleteSource, then click the arrow of its combo box and select
CustomSource
- Click AutoCompleteMode, then click the arrow of its combo box and select
Accept
- On the form, double-click the Calculate button and implement its event as
follows:
Private Sub btnCalculateClick(ByVal sender As Object,
ByVal e As System.EventArgs)
Handles btnCalculate.Click
Dim Monday1 As Double, Tuesday1 As Double
Dim Wednesday1 As Double, Thursday1 As Double
Dim Friday1 As Double, Saturday1 As Double, Sunday1 As Double
Dim Monday2 As Double, Tuesday2 As Double
Dim Wednesday2 As Double, Thursday2 As Double
Dim Friday2 As Double, Saturday2 As Double
Dim Sunday2 As Double, TotalHoursWeek1 As Double
Dim TotalHoursWeek2 As Double
Dim regHours1 As Double, regHours2 As Double
Dim ovtHours1 As Double, ovtHours2 As Double
Dim regAmount1 As Double, regAmount2 As Double
Dim ovtAmount1 As Double, ovtAmount2 As Double
Dim RegularHours As Double, OvertimeHours As Double
Dim RegularAmount As Double, OvertimeAmount As Double
Dim TotalEarnings As Double, HourlySalary As Double
' Retrieve the hourly salary
Try
hourlySalary = CDbl(txtHourlySalary.Text)
Catch
MsgBox("The value you typed for the salary is invalid" &
vbCrLf & "Please try again")
txtHourlySalary.Focus()
End Try
' Retrieve the value of each day worked
Try
monday1 = CDbl(txtMonday1.Text)
Catch
MsgBox("You typed an invalid value" & vbCrLf &
"Please try again")
txtMonday1.Focus()
End Try
Try
tuesday1 = CDbl(txtTuesday1.Text)
Catch
MsgBox("You typed an invalid value" & vbCrLf &
"Please try again")
txtTuesday1.Focus()
End Try
Try
wednesday1 = CDbl(txtWednesday1.Text)
Catch
MsgBox("You typed an invalid value" & vbCrLf &
"Please try again")
txtWednesday1.Focus()
End Try
Try
thursday1 = CDbl(txtThursday1.Text)
Catch
MsgBox("You typed an invalid value" & vbCrLf &
"Please try again")
txtThursday1.Focus()
End Try
Try
friday1 = CDbl(txtFriday1.Text)
Catch
MsgBox("You typed an invalid value" & vbCrLf &
"Please try again")
txtFriday1.Focus()
End Try
Try
saturday1 = CDbl(txtSaturday1.Text)
Catch
MsgBox("You typed an invalid value" & vbCrLf &
"Please try again")
txtSaturday1.Focus()
End Try
Try
sunday1 = CDbl(txtSunday1.Text)
Catch
MsgBox("You typed an invalid value" & vbCrLf &
"Please try again")
txtSunday1.Focus()
End Try
Try
monday2 = CDbl(txtMonday2.Text)
Catch
MsgBox("You typed an invalid value" & vbCrLf &
"Please try again")
txtMonday2.Focus()
End Try
Try
tuesday2 = CDbl(txtTuesday2.Text)
Catch
MsgBox("You typed an invalid value" & vbCrLf &
"Please try again")
txtTuesday2.Focus()
End Try
Try
wednesday2 = CDbl(txtWednesday2.Text)
Catch
MsgBox("You typed an invalid value" & vbCrLf &
"Please try again")
txtWednesday2.Focus()
End Try
Try
thursday2 = CDbl(txtThursday2.Text)
Catch
MsgBox("You typed an invalid value" & vbCrLf &
"Please try again")
txtThursday2.Focus()
End Try
Try
friday2 = CDbl(txtFriday2.Text)
Catch
MsgBox("You typed an invalid value" & vbCrLf &
"Please try again")
txtFriday2.Focus()
End Try
Try
saturday2 = CDbl(txtSaturday2.Text)
Catch
MsgBox("You typed an invalid value" & vbCrLf &
"Please try again")
txtSaturday2.Focus()
End Try
Try
sunday2 = CDbl(txtSunday2.Text)
Catch
MsgBox("You typed an invalid value" & vbCrLf &
"Please try again")
txtSunday2.Focus()
End Try
' Calculate the total number of hours for each week
totalHoursWeek1 = monday1 + tuesday1 + wednesday1 +
thursday1 + friday1 + saturday1 + sunday1
totalHoursWeek2 = monday2 + tuesday2 + wednesday2 +
thursday2 + friday2 + saturday2 + sunday2
' The overtime is paid time and half
Dim ovtSalary As Double = HourlySalary * 1.5
' If the employee worked under 40 hours, there is no overtime
If TotalHoursWeek1 < 40 Then
regHours1 = TotalHoursWeek1
regAmount1 = HourlySalary * regHours1
ovtHours1 = 0.0
ovtAmount1 = 0.0
' If the employee worked over 40 hours, calculate the overtime
ElseIf TotalHoursWeek1 >= 4 Then
regHours1 = 40
regAmount1 = HourlySalary * 40
ovtHours1 = TotalHoursWeek1 - 40
ovtAmount1 = ovtHours1 * ovtSalary
End If
If TotalHoursWeek2 < 40 Then
regHours2 = TotalHoursWeek2
regAmount2 = HourlySalary * regHours2
ovtHours2 = 0.0
ovtAmount2 = 0.0
ElseIf TotalHoursWeek2 >= 40 Then
regHours2 = 40
regAmount2 = HourlySalary * 40
ovtHours2 = TotalHoursWeek2 - 40
ovtAmount2 = ovtHours2 * ovtSalary
End If
RegularHours = regHours1 + regHours2
OvertimeHours = ovtHours1 + ovtHours2
RegularAmount = regAmount1 + regAmount2
OvertimeAmount = ovtAmount1 + ovtAmount2
TotalEarnings = RegularAmount + OvertimeAmount
txtRegularTime.Text = RegularHours.ToString("F")
txtOvertime.Text = OvertimeHours.ToString("F")
txtRegularAmount.Text = RegularAmount.ToString("F")
txtOvertimeAmount.Text = OvertimeAmount.ToString("F")
txtNetPay.Text = TotalEarnings.ToString("F")
End Sub
|
- Execute the application to see the result
- Close the form and return to your programming environment
Download
|
|