-
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
-
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
-
This didn't work.
It returns a value of $290.00
My entry returns $2900.00
Should be 2935.13
-
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)
-
When I try this I get an error.
I can see that it is returning tPay as
290270168354.8753...
-
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.