hi, I am struggling trying to put a validation into an exsisting peice of code for an exercise i have got at college.
the validation that needs to be inserted is
The Pay Grade must be a single, uppercase character (M, L, T, or F) when entered into the input box. with the appropriate error message displayed in msgbox if entered incorectly.
I also need to put validations in for the Employee Number and No of hours worked, but i have managed to do these, it's just the paygrade i am very stuck on.
anybody help me please ??
Private Sub Command1_Click( )
Dim EmployeeNo As Integer
Dim PayGrade As String
Dim HoursWorked As Integer
Dim TotalShiftPay As Double
Dim TotalEmployeesP rocessed As Single
Dim TotalManagement Pay As Double
Dim TotalOtherPay As Double
Dim TotalMonthlyShi ftPay As Double
ManagementFlatR ate = 250 ' Variables for the Total Shift Pay Calculations
ManagementRate = 30 ' "" " " " " " ""
LabourerRate = 15 ' "" " " " " " ""
TurnerRate = 20 ' "" " " " " " ""
FitterRate = 25 ' "" " " " " " ""
'1A_Prog
'2A 'Print Column Headers
Picture1.AutoRe draw = True
Picture1.Cls ' clears the Picture box
Picture1.FontBo ld = True ' makes font bold
Picture1.FontSi ze = 12 ' sets the font size for the headers
Picture1.Print ; "Employee No"; Space$(8); "Pay Grade"; Space$(8); "No. Of Hours Worked"; _
Space$(8); "Total Shift Pay"
Picture1.FontBo ld = False ' Bold off
Picture1.FontSi ze = 10 ' Fontsize set back to 10
Picture1.Print ' prints a blank line
'Enter Employee Number
EmployeeNo = InputBox("Enter Employee Number")
'2B
'3A
Do Until (EmployeeNo) = "999"
If EmployeeNo < 1 Or EmployeeNo > 999 Then
MsgBox ("Invalid Employee Number - Must be between 1 and 999 , Please Re-Enter Employee No.")
'4A
Else
PayGrade = InputBox("Enter Pay Grade")
HoursWorked = InputBox("Enter number of hours worked")
If HoursWorked > 200 Or HoursWorked < 1 Then
MsgBox "Total hours can not exceed 200 and can not be less then 1. Try again."
HoursWorked = 0
HoursWorked = InputBox("Enter number of hours worked")
End If
'4B
'5A. Calculate Total Shift Pay and Total Monthly Shift Pay
'6A
If PayGrade = "M" Then
TotalShiftPay = (ManagementRate * HoursWorked) + ManagementFlatR ate
TotalManagement Pay = TotalManagement Pay + TotalShiftPay
End If
'6B
If PayGrade = "L" Then
TotalShiftPay = (LabourerRate * 1.5) * HoursWorked
TotalOtherPay = TotalOtherPay + TotalShiftPay
End If
'6C
If PayGrade = "T" Then
TotalShiftPay = (TurnerRate * 1.5) * HoursWorked
TotalOtherPay = TotalOtherPay + TotalShiftPay
End If
'6D
If PayGrade = "F" Then
TotalShiftPay = (FitterRate * 1.5) * HoursWorked
TotalOtherPay = TotalOtherPay + TotalShiftPay
End If
'4C Display Indiviual Record
Picture1.Print Space(10); Format(Employee No, "@@@"); Space(45); PayGrade; Space(43); _
Format(HoursWor ked, "@@@"); Space(57); " £ "; Format(FormatNu mber(TotalShift Pay), "@@@@@@@@@" )
'4D Incrament Employees Processed
TotalEmployeesP rocessed = TotalEmployeesP rocessed + 1
End If
'4E Enter Employee Number
EmployeeNo = InputBox("Enter Employee Number")
Loop
'2C Calculate the total Monthly ShiftPay for All paygrades
TotalMonthlyShi ftPay = TotalManagement Pay + TotalOtherPay
'2C Display the final Output
Picture1.Print ""
Picture1.Print ""
Picture1.Print "Total number of employees processed "; Tab(55); _
Format(TotalEmp loyeesProcessed , "@@@@@@@@@@ ")
Picture1.Print "Total monthly shift pay for management "; Tab(55); "£ "; _
Format(FormatNu mber(TotalManag ementPay), "@@@@@@@@@@ ")
Picture1.Print "Total monthly shift pay for other grades "; Tab(55); "£ "; _
Format(FormatNu mber(TotalOther Pay), "@@@@@@@@@@ ")
Picture1.Print "Total of all shift pay "; Tab(55); "£ "; _
Format(FormatNu mber(TotalManag ementPay + TotalOtherPay), "@@@@@@@@@@ ")
Picture1.Print ""
Picture1.Print ""
Picture1.Print "--------------------------------------------------------------------"
End Sub
the validation that needs to be inserted is
The Pay Grade must be a single, uppercase character (M, L, T, or F) when entered into the input box. with the appropriate error message displayed in msgbox if entered incorectly.
I also need to put validations in for the Employee Number and No of hours worked, but i have managed to do these, it's just the paygrade i am very stuck on.
anybody help me please ??
Private Sub Command1_Click( )
Dim EmployeeNo As Integer
Dim PayGrade As String
Dim HoursWorked As Integer
Dim TotalShiftPay As Double
Dim TotalEmployeesP rocessed As Single
Dim TotalManagement Pay As Double
Dim TotalOtherPay As Double
Dim TotalMonthlyShi ftPay As Double
ManagementFlatR ate = 250 ' Variables for the Total Shift Pay Calculations
ManagementRate = 30 ' "" " " " " " ""
LabourerRate = 15 ' "" " " " " " ""
TurnerRate = 20 ' "" " " " " " ""
FitterRate = 25 ' "" " " " " " ""
'1A_Prog
'2A 'Print Column Headers
Picture1.AutoRe draw = True
Picture1.Cls ' clears the Picture box
Picture1.FontBo ld = True ' makes font bold
Picture1.FontSi ze = 12 ' sets the font size for the headers
Picture1.Print ; "Employee No"; Space$(8); "Pay Grade"; Space$(8); "No. Of Hours Worked"; _
Space$(8); "Total Shift Pay"
Picture1.FontBo ld = False ' Bold off
Picture1.FontSi ze = 10 ' Fontsize set back to 10
Picture1.Print ' prints a blank line
'Enter Employee Number
EmployeeNo = InputBox("Enter Employee Number")
'2B
'3A
Do Until (EmployeeNo) = "999"
If EmployeeNo < 1 Or EmployeeNo > 999 Then
MsgBox ("Invalid Employee Number - Must be between 1 and 999 , Please Re-Enter Employee No.")
'4A
Else
PayGrade = InputBox("Enter Pay Grade")
HoursWorked = InputBox("Enter number of hours worked")
If HoursWorked > 200 Or HoursWorked < 1 Then
MsgBox "Total hours can not exceed 200 and can not be less then 1. Try again."
HoursWorked = 0
HoursWorked = InputBox("Enter number of hours worked")
End If
'4B
'5A. Calculate Total Shift Pay and Total Monthly Shift Pay
'6A
If PayGrade = "M" Then
TotalShiftPay = (ManagementRate * HoursWorked) + ManagementFlatR ate
TotalManagement Pay = TotalManagement Pay + TotalShiftPay
End If
'6B
If PayGrade = "L" Then
TotalShiftPay = (LabourerRate * 1.5) * HoursWorked
TotalOtherPay = TotalOtherPay + TotalShiftPay
End If
'6C
If PayGrade = "T" Then
TotalShiftPay = (TurnerRate * 1.5) * HoursWorked
TotalOtherPay = TotalOtherPay + TotalShiftPay
End If
'6D
If PayGrade = "F" Then
TotalShiftPay = (FitterRate * 1.5) * HoursWorked
TotalOtherPay = TotalOtherPay + TotalShiftPay
End If
'4C Display Indiviual Record
Picture1.Print Space(10); Format(Employee No, "@@@"); Space(45); PayGrade; Space(43); _
Format(HoursWor ked, "@@@"); Space(57); " £ "; Format(FormatNu mber(TotalShift Pay), "@@@@@@@@@" )
'4D Incrament Employees Processed
TotalEmployeesP rocessed = TotalEmployeesP rocessed + 1
End If
'4E Enter Employee Number
EmployeeNo = InputBox("Enter Employee Number")
Loop
'2C Calculate the total Monthly ShiftPay for All paygrades
TotalMonthlyShi ftPay = TotalManagement Pay + TotalOtherPay
'2C Display the final Output
Picture1.Print ""
Picture1.Print ""
Picture1.Print "Total number of employees processed "; Tab(55); _
Format(TotalEmp loyeesProcessed , "@@@@@@@@@@ ")
Picture1.Print "Total monthly shift pay for management "; Tab(55); "£ "; _
Format(FormatNu mber(TotalManag ementPay), "@@@@@@@@@@ ")
Picture1.Print "Total monthly shift pay for other grades "; Tab(55); "£ "; _
Format(FormatNu mber(TotalOther Pay), "@@@@@@@@@@ ")
Picture1.Print "Total of all shift pay "; Tab(55); "£ "; _
Format(FormatNu mber(TotalManag ementPay + TotalOtherPay), "@@@@@@@@@@ ")
Picture1.Print ""
Picture1.Print ""
Picture1.Print "--------------------------------------------------------------------"
End Sub