Solved

Record totals

Posted on 2004-10-26
171 Views
Last Modified: 2010-05-02
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.
0
Question by:itcopt
    3 Comments
     
    LVL 18

    Accepted Solution

    by:
    pdblGrossTotal = CDbl(dtEmployees.Rows(pintCount).Item("fldGrossPay"))
    0
     
    LVL 8

    Expert Comment

    by:bramsquad
    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
     
    LVL 14

    Expert Comment

    by:Shiju Sasidharan
    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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
    Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
    Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
    Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

    884 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now