?
Solved

Calculation

Posted on 2006-06-06
12
Medium Priority
?
250 Views
Last Modified: 2010-04-07
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$

Please help me with it
0
Comment
Question by:DickSwart6
  • 6
  • 3
9 Comments
 
LVL 54

Expert Comment

by:Ryan Chong
ID: 16841480
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
 
LVL 54

Expert Comment

by:Ryan Chong
ID: 16841485
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
 
LVL 54

Accepted Solution

by:
Ryan Chong earned 252 total points
ID: 16841506
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 46

Expert Comment

by:aikimark
ID: 16842360
@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
 
LVL 54

Expert Comment

by:Ryan Chong
ID: 16842948
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
 
LVL 54

Expert Comment

by:Ryan Chong
ID: 16844099
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
 
LVL 46

Assisted Solution

by:aikimark
aikimark earned 248 total points
ID: 16844328
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
 
LVL 54

Expert Comment

by:Ryan Chong
ID: 16844411
ugly but works, thanks learn something today.
0
 
LVL 46

Expert Comment

by:aikimark
ID: 16845038
@ryancys

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

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses
Course of the Month17 days, 5 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question