I have a problem with this particular piece of coding I have for my payroll system in Visual Basic 6. I am basically trying to calculate the wages of employee's by entering in the number of hours they have worked. The criteria of how much pay they receive works like this:
If they work the standard 40 hours or less, they get paid number of hours x $5.5
e.g. 40 hours x $5.50 = $220
If they work between 41-50 hours (which is considered as overtime), they get 40 hours of pay PLUS an extra $1.50 per hour
e.g. 45 hours (40 hours x $5.50) + (5 additional hours x $5.50 x $1.50) = $261.25
If they work between 51-60 hours (again considered as overtime), they get an extra $2.50 an hour, while adding the other $1.50 per hour they have worked for the other overtime hours
e.g. 52 hours (40 x $5.50) + (10 additional hours x $5.50 x $1.50) + (2 additional hours x $5.50 x $2.50) = $330
I have written this code up to calculate this:
Private Sub cmdCalculate_Click() Hours = txthoursworked If Hours > 0 <= 40 Then lblgrosspay = (Hours * 5.5) ElseIf Hours > 41 <= 50 Then lblgrosspay = (Hours * 5.5) * 1.5 ElseIf Hours > 51 <= 60 Then lblgrosspay = (Hours * 5.5) * 2.5 End If
But this code is not working properly.
If I enter anything between 0 to 40, the code works properly (e.g. 40 hours -> $220). But if I enter anything more, such as 47 hours, it does not calculate the additional overtime pay that should be added onto it (e.g. 47 hours should be $277.75) but it keeps coming up as $258.50 (not multiplying the extra 1.5).
I think the code I have written quite wrong, but I do not understand how I can fix it up. I think an extra overtime box may be required, but I am not sure how I can do that either. Any help would be appreciated, thanks.