Results 1 to 5 of 5

Thread: Payroll Calculator

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2000
    Posts
    18

    Post

    My payroll calculator gives the wrong answer and i am pretty sure my code is right. It is supposed to give time and a half for hours worked over 40 but gives the wrong answer, it does give the right answer for hours under 40 though, here is the code: What's wrong?

    Dim inthours As Integer
    Dim intrate As Integer
    Dim intgross As Integer
    inthours = txthours.Text
    intrate = txtrate.Text
    If inthours > 40 Then
    intrate = intrate * 1.5
    lblgross.Caption = inthours * intrate
    ElseIf inthours <= 40 Then
    intrate = intrate
    lblgross.Caption = inthours * intrate
    End If
    End Sub

  2. #2
    Fanatic Member
    Join Date
    Oct 1999
    Location
    MA, USA
    Posts
    523

    Post

    This seems to work for me:
    Code:
    Private Sub Command1_Click()
        Dim intHours As Integer
        Dim intRate As Integer
        Dim intGross As Integer
        
        intHours = txthours.Text
        intRate = txtrate.Text
        
        If intHours > 40 Then
            lblgross.Caption = 40 * intRate 'I added this line...
            intRate = intRate * 1.5
            lblgross.Caption = lblgross.Caption + (intHours - 40) * intRate '...and modified this one
        ElseIf intHours <= 40 Then
            intRate = intRate
            lblgross.Caption = intHours * intRate
        End If
    End Sub
    Also when you defined IntRate as Integer: it only works for even numbers, if your rate is odd, then 1.5 of it will always be .5 too much (hope you know what I mean - it simply rounds it)
    ------------------
    Visual Basic Programmer
    ------------------
    PolComSoft
    You will hear a lot about it.

    [This message has been edited by QWERTY (edited 02-19-2000).]

  3. #3
    Addicted Member
    Join Date
    Jul 1999
    Location
    Portland, OR.
    Posts
    226

    Post

    Hi.

    Worked hours = 60
    Rate = 6
    Hint, The way to do it:

    (40 * 6) + (20 + 9)

    QWERTY, Int gives the Integer part only. 1.5 => 1

    Good Luck.

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Feb 2000
    Posts
    18

    Post

    Thanks, I understand it now. And changed the rate one's to currency and did the other stuff. Thanks.

  5. #5
    Fanatic Member
    Join Date
    Oct 1999
    Location
    MA, USA
    Posts
    523

    Post

    Actually Lyla 1.5 = 2 if you have variable defined as integer. Checked it, I can't be wrong.

    ------------------
    Visual Basic Programmer
    ------------------
    PolComSoft
    You will hear a lot about it.


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