Record totals

Hello,


I am working on a program and I need to add  all fields for a running total. Here is the code

 Private Sub Totals()
        Dim pintCount As Integer
        Dim pdblGrossTotal As Double
        Dim pdblWithholding As Double
        Dim pdblNetPay As Double
        Dim dtEmployees As DataTable

        For pintCount = 0 To dtEmployees.Rows.Count - 1
            pdblGrossTotal = dtEmployees.Rows(pintCount).Item("fldGrossPay")
            txtGross.Text = pdblGrossTotal.ToString
        Next

        For pintCount = 0 To dtEmployees.Rows.Count - 1
            pdblWithholding = dtEmployees.Rows(pintCount).Item("fldWithholding")
            txtWithholding.Text = pdblWithholding.ToString
        Next

        For pintCount = 0 To dtEmployees.Rows.Count - 1
            pdblNetPay = dtEmployees.Rows(pintCount).Item("fldNetPay")
            txtNetPay.Text = pdblNetPay.ToString
        Next

    End Sub

*** I am getting an error on the line              -     pdblGrossTotal = dtEmployees.Rows(pintCount).Item("fldGrossPay")

The error is " options strict on disallows implicit conversions from system objects to double.  How do I convert a system object to a double?

Thanks.
itcoptAsked:
Who is Participating?
 
bobbit31Commented:
pdblGrossTotal = CDbl(dtEmployees.Rows(pintCount).Item("fldGrossPay"))
0
 
bramsquadCommented:
also if you want a running total youll have to do this

pdblGrossTotal = pdblGrossTotal + CDbl(dtEmployees.Rows(pintCount).Item("fldGrossPay"))

otherwise its just going to grab the last value

~b
0
 
Shiju SasidharanAssoc Project ManagerCommented:
hI
try the whole thing in the same loop
like this
'-----------------------------------------------------------------
        For pintCount = 0 To dtEmployees.Rows.Count - 1
               pdblGrossTotal =  pdblGrossTotal  + CDbl(dtEmployees.Rows(pintCount).Item("fldGrossPay"))
              pdblWithholding = pdblWithholding  + CDbl(dtEmployees.Rows(pintCount).Item("fldWithholding"))
              pdblNetPay = pdblNetPay + CDbl(dtEmployees.Rows(pintCount).Item("fldNetPay"))
         Next pintCount

         txtGross.Text = pdblGrossTotal
         txtWithholding.Text = pdblWithholding
         txtNetPay.Text = pdblNetPay
'---------------------------------------------------------------------------------------------------

;-)
Shiju
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.