Results 1 to 5 of 5

Thread: Overtime Calculation?

  1. #1

    Thread Starter
    Member Suidae's Avatar
    Join Date
    Nov 2001
    Posts
    52

    Overtime Calculation?

    Can this routine be done more efficiently? If so how?

    Thanks!

    VB Code:
    1. Private Sub Command1_Click()
    2.    
    3.     Dim Hours As Double ' Number of Hours Worked
    4.     Dim Th As Double 'OverTime
    5.     Dim Dt As Double 'DoubleTime
    6.    
    7.     Dim Base As Currency 'Employee's Base Hourly Base Rate
    8.     Dim Net As Currency ' Employee's Net Payroll Amount
    9.    
    10.     Hours = Val(txtHours.Text) ' Hours Worked
    11.     Base = 10 ' Employee Hourly Rate
    12.    
    13.  
    14.     If Hours <= 40 Then
    15.         Net = (Hours * Base)
    16.     ElseIf (Hours >= 40.01) And (Hours <= 60) Then
    17.         Th = (Hours - 40)
    18.         Net = (40 * Base) + (Th * Base * 1.5)
    19.     ElseIf Hours >= 60.01 Then
    20.         Dt = (Hours - 40 - 20)
    21.         Net = (40 * Base) + (20 * Base * 1.5) + (Dt * Base * 2)
    22.     End If
    23.    
    24.     txtNet.Text = Net
    25.    
    26. End Sub
    I'm a misanthropic philanthropist!
    Frog, the only white meat...

  2. #2
    Fanatic Member Mr.No's Avatar
    Join Date
    Sep 2002
    Location
    Mauritius
    Posts
    651
    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 ...

  3. #3
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141
    How about this?
    VB Code:
    1. Private Sub Command1_Click()
    2. Dim Hours As Double ' Number of Hours Worked
    3. Dim Th As Double 'OverTime
    4. Dim Dt As Double 'DoubleTime
    5.    
    6. Dim Base As Currency 'Employee's Base Hourly Base Rate
    7. Dim Net As Currency ' Employee's Net Payroll Amount
    8.    
    9. Hours = Val(txtHours.Text) ' Hours Worked
    10. Base = 10 ' Employee Hourly Rate
    11.    
    12.     Select Case Hours
    13.         Case Is > 60
    14.             Net = (40 * Base) + (20 * (Base * 1.5)) + ((60 - Hours) * (2 * Base))
    15.         Case Is > 40
    16.             Net = (40 * Base) + ((Hours - 40) * (Base * 1.5))
    17.         Case Else
    18.             Net = Hours * Base
    19.     End Select
    20.  
    21.     txtNet.Text = Net
    22.    
    23. End Sub

  4. #4
    Frenzied Member Shawn N's Avatar
    Join Date
    Dec 2001
    Location
    Houston
    Posts
    1,631
    Originally posted by MarkT
    How about this?
    VB Code:
    1. Private Sub Command1_Click()
    2. Dim Hours As Double ' Number of Hours Worked
    3. Dim Th As Double 'OverTime
    4. Dim Dt As Double 'DoubleTime
    5.    
    6. Dim Base As Currency 'Employee's Base Hourly Base Rate
    7. Dim Net As Currency ' Employee's Net Payroll Amount
    8.    
    9. Hours = Val(txtHours.Text) ' Hours Worked
    10. Base = 10 ' Employee Hourly Rate
    11.    
    12.     Select Case Hours
    13.         Case Is > 60
    14.             Net = (40 * Base) + (20 * (Base * 1.5)) + (([color="#FF0000"]Hours - 60[/color]) * (2 * Base))
    15.         Case Is > 40
    16.             Net = (40 * Base) + ((Hours - 40) * (Base * 1.5))
    17.         Case Else
    18.             Net = Hours * Base
    19.     End Select
    20.  
    21.     txtNet.Text = Net
    22.    
    23. End Sub

  5. #5
    PowerPoster
    Join Date
    Jun 2001
    Location
    Trafalgar, IN
    Posts
    4,141
    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
  •  



Click Here to Expand Forum to Full Width