|
-
Jan 21st, 2003, 12:19 PM
#1
Thread Starter
Member
Overtime Calculation?
Can this routine be done more efficiently? If so how?
Thanks!
VB Code:
Private Sub Command1_Click()
Dim Hours As Double ' Number of Hours Worked
Dim Th As Double 'OverTime
Dim Dt As Double 'DoubleTime
Dim Base As Currency 'Employee's Base Hourly Base Rate
Dim Net As Currency ' Employee's Net Payroll Amount
Hours = Val(txtHours.Text) ' Hours Worked
Base = 10 ' Employee Hourly Rate
If Hours <= 40 Then
Net = (Hours * Base)
ElseIf (Hours >= 40.01) And (Hours <= 60) Then
Th = (Hours - 40)
Net = (40 * Base) + (Th * Base * 1.5)
ElseIf Hours >= 60.01 Then
Dt = (Hours - 40 - 20)
Net = (40 * Base) + (20 * Base * 1.5) + (Dt * Base * 2)
End If
txtNet.Text = Net
End Sub
I'm a misanthropic philanthropist!
Frog, the only white meat...
-
Jan 21st, 2003, 12:26 PM
#2
Fanatic Member
Well to begin with you could round your final result. And secondly I would localise the calculation of the overtime into a class.
Using VB.NET 2003/.NET 1.1/C# 2.0
http://del.icio.us/rajoo
Blow your mind, smoke gunpowder
Ashes to ashes, dust to dust
If God won't have you, the devil will. - Author unknown
Don't follow me, I'm lost too ...
-
Jan 21st, 2003, 12:42 PM
#3
How about this?
VB Code:
Private Sub Command1_Click()
Dim Hours As Double ' Number of Hours Worked
Dim Th As Double 'OverTime
Dim Dt As Double 'DoubleTime
Dim Base As Currency 'Employee's Base Hourly Base Rate
Dim Net As Currency ' Employee's Net Payroll Amount
Hours = Val(txtHours.Text) ' Hours Worked
Base = 10 ' Employee Hourly Rate
Select Case Hours
Case Is > 60
Net = (40 * Base) + (20 * (Base * 1.5)) + ((60 - Hours) * (2 * Base))
Case Is > 40
Net = (40 * Base) + ((Hours - 40) * (Base * 1.5))
Case Else
Net = Hours * Base
End Select
txtNet.Text = Net
End Sub
-
Jan 21st, 2003, 12:57 PM
#4
Frenzied Member
Originally posted by MarkT
How about this?
VB Code:
Private Sub Command1_Click()
Dim Hours As Double ' Number of Hours Worked
Dim Th As Double 'OverTime
Dim Dt As Double 'DoubleTime
Dim Base As Currency 'Employee's Base Hourly Base Rate
Dim Net As Currency ' Employee's Net Payroll Amount
Hours = Val(txtHours.Text) ' Hours Worked
Base = 10 ' Employee Hourly Rate
Select Case Hours
Case Is > 60
Net = (40 * Base) + (20 * (Base * 1.5)) + (([color="#FF0000"]Hours - 60[/color]) * (2 * Base))
Case Is > 40
Net = (40 * Base) + ((Hours - 40) * (Base * 1.5))
Case Else
Net = Hours * Base
End Select
txtNet.Text = Net
End Sub
-
Jan 21st, 2003, 04:55 PM
#5
Originally posted by Shawn N
Net = (40 * Base) + (20 * (Base * 1.5)) + ((Hours - 60 ) * (2 * Base))
Yes that is right!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|