Results 1 to 6 of 6

Thread: Cannot get total (beginner)

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2000
    Posts
    47
    I cannot see why my total doesn't figure correctly.

    Option Explicit

    Private Sub cmdExit_Click()
    End
    End Sub

    Private Sub cmdOutput_Click()
    Dim empName As String, hrRate As String, hrWork As Single, _
    grPay As String, totPay As String, fmt As String, i As Single, _
    tpay As String
    'display payroll report
    picOutput.Cls
    picOutput.Print "Payroll Report for Week ending 4/15/99"
    picOutput.Print ""
    picOutput.Print "Employee"; Tab(15); "Hourly Rate"; Tab(30);
    picOutput.Print "Hours worked"; Tab(45); "Gross Pay"
    fmt = "@@@@@@@@@@"
    Open App.Path & "\Payroll.txt" For Input As #1
    totPay = 0
    grPay = 0
    For i = 1 To 10
    Input #1, empName, hrRate, hrWork
    If hrWork <= 40 Then
    grPay = hrWork * hrRate
    ElseIf hrWork > 40 Then
    grPay = (40 * hrRate) + (hrWork - 40) * (hrRate * 1.5)
    End If
    tpay = (grPay + totPay)
    hrRate = FormatCurrency(hrRate)
    grPay = FormatCurrency(grPay)
    picOutput.Print empName; Tab(15); Format(hrRate, fmt); Tab(29);
    picOutput.Print hrWork; Tab(42); Format(grPay, fmt)
    Next i
    Close #1
    tpay = FormatCurrency(tpay)
    picOutput.Print ""
    picOutput.Print "Final Total"; Tab(15); Format(tpay, fmt)
    End Sub




  2. #2
    Junior Member
    Join Date
    Sep 1999
    Posts
    19
    see if this helps:

    Option Explicit

    Private Sub cmdExit_Click()
    End
    End Sub

    Private Sub cmdOutput_Click()
    Dim empName As String, hrRate As String, hrWork As Single, _
    grPay As String, totPay As String, fmt As String, i As Single, _
    tpay As String
    'display payroll report
    picOutput.Cls
    picOutput.Print "Payroll Report for Week ending 4/15/99"
    picOutput.Print ""
    picOutput.Print "Employee"; Tab(15); "Hourly Rate"; Tab(30);
    picOutput.Print "Hours worked"; Tab(45); "Gross Pay"
    fmt = "@@@@@@@@@@"
    Open App.Path & "\Payroll.txt" For Input As #1
    totPay = 0
    grPay = 0
    For i = 1 To 10
    Input #1, empName, hrRate, hrWork
    If hrWork <= 40 Then
    grPay = hrWork * hrRate
    ElseIf hrWork > 40 Then
    grPay = (40 * hrRate) + (hrWork - 40) * (hrRate * 1.5)
    End If
    totPay = (Val(grPay) + Val(totPay))
    hrRate = FormatCurrency(hrRate)
    grPay = FormatCurrency(grPay)
    picOutput.Print empName; Tab(15); Format(hrRate, fmt); Tab(29);
    picOutput.Print hrWork; Tab(42); Format(grPay, fmt)
    Next i
    Close #1
    tpay = FormatCurrency(totPay)
    picOutput.Print ""
    picOutput.Print "Final Total"; Tab(15); Format(tpay, fmt)
    End Sub

  3. #3

    Thread Starter
    Member
    Join Date
    Feb 2000
    Posts
    47
    This didn't work.

    It returns a value of $290.00

    My entry returns $2900.00

    Should be 2935.13

  4. #4
    Frenzied Member
    Join Date
    Aug 1999
    Location
    Santa Clara, Ca , 95058
    Posts
    1,105
    Shouldn't

    tpay = (grPay + totPay)


    be

    tpay = grPay + tPay

    ?

    I would also define tpay as currency and convert it prior to printing it:

    picOutput.Print "Final Total"; Tab(15); Format(Cstr(tpay), fmt)

  5. #5

    Thread Starter
    Member
    Join Date
    Feb 2000
    Posts
    47
    When I try this I get an error.

    I can see that it is returning tPay as
    290270168354.8753...
    MomOf3CollegeStudentTooMuchToDoNeverEnoughTime

    Using VB6 Working Model Edition

  6. #6
    Frenzied Member
    Join Date
    Aug 1999
    Location
    Santa Clara, Ca , 95058
    Posts
    1,105
    Probably because your format string is 10 chars long and the output you're displaying is at least 17.

    You've got two choices. You can post the data here or you can step thru the code and observe the value(s) of the data being read.

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