# Calculation

Hi All,
I need to work out how mutch pay an employee should resceive. I want to enter the hourly rate in a text box and when I click a button It should give me two answers. Example : Normal work hours is 9 hours and every employee has their own hourly rate. Mark's rate is 5 \$. if a employee work overtime (more than 9 hours) they should get paid overtime (Hours over 9 * 1.5).

If I Mark work 10 hours I need two results.
Normal Pay = 45\$
Overtime Pay = 7.5\$

###### Who is Participating?

Commented:
so...

normalworkinghour = 9
totalWorkingHour = 10
NormalPay = ((totalWorkingHour - (totalWorkingHour Mod normalworkinghour)) * 5)
OvertimePay = ((totalWorkingHour - normalworkinghour) * 5 * 1.5)
totalPay = NormalPay + OvertimePay
MsgBox NormalPay & "+" & OvertimePay & "=" & totalPay
0

Commented:
I thought if working 10 hours is 55\$ here?

totalWorkingHour = 10
totalPay = ((totalWorkingHour - (totalWorkingHour Mod 8)) * 5) + ((totalWorkingHour - 8) * 5 * 1.5)
MsgBox totalPay
0

Commented:
sorry, the normal rate above is 8 hours, try this instead for 9 hours...

totalWorkingHour = 10
totalPay = ((totalWorkingHour - (totalWorkingHour Mod 9)) * 5) + ((totalWorkingHour - 9) * 5 * 1.5)
MsgBox totalPay
0

Commented:
@ryancys

I don't think MOD is the correct operator to use in this solution.  If this is a real-world example, then it is possible for an employee to work a very long day.  Using the MOD operator, the pay calculations would be low.
I would suggest:
Function Pay(HrsWorked, NormalPayRate, Optional NormalHrs As Single = 9) As Currency
Dim NormalPay As Currency
Dim OvertimePay As Currency
If HrsWorked <= NormalHrs Then
NormalPay = (HrsWorked * NormalPayRate)
OvertimePay = 0
Else
NormalPay = (NormalHrs * NormalPayRate)
OvertimePay = ((HrsWorked - NormalHrs) * NormalPayRate * 1.5)
End If

Pay = NormalPay + OvertimePay

End Function
0

Commented:
Nice argument aikimark, what i approached is actually try to avoid a "IF" statement (Don't ask me why just try to do it without a "IF" statement..) So that's why you see a bit 'weird' on my suggestion above.
0

Commented:
Had to admit need using "IF" condition here, the Mod function may not best suitable to solve the above function.

Here is my version, but yes, NO POINTS for this as already posted by aikimark.

normalworkinghour = 9
totalWorkingHour = 25
hourRate = 5
OTRate = 1.5

NormalPay = IIf(totalWorkingHour > normalworkinghour, normalworkinghour, totalWorkingHour) * hourRate
OvertimePay = IIf(totalWorkingHour > normalworkinghour, (totalWorkingHour - normalworkinghour) * hourRate * OTRate, 0)
totalPay = NormalPay + OvertimePay
MsgBox NormalPay & "+" & OvertimePay & "=" & totalPay

Thanks aikimark for correction, cheers ; )
0

Commented:
Calcuatum Absurdum (without If/Select -like construct):

Pay = ((-1 * (HrsWorked > NormalHrs)) * (NormalHrs * NormalPayRate))
+ ((-1 * (HrsWorked <= NormalHrs)) * (HrsWorked * NormalPayRate))
+ ((-1 * (HrsWorked > NormalHrs)) * ((HrsWorked - NormalHrs) * NormalPayRate * 1.5))

sure looks ugly to me.
0

Commented:
ugly but works, thanks learn something today.
0

Commented:
@ryancys

However, this ugly code is subject to errors, since it assumes that the inputs are all numeric.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.