Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Record totals

Posted on 2004-10-26
3
Medium Priority
?
174 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
Comment
Question by:itcopt
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 18

Accepted Solution

by:
bobbit31 earned 500 total points
ID: 12414934
pdblGrossTotal = CDbl(dtEmployees.Rows(pintCount).Item("fldGrossPay"))
0
 
LVL 8

Expert Comment

by:bramsquad
ID: 12415112
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
ID: 12415540
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

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

610 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