Solved

Problem Converting Double

Posted on 2010-11-23
2
190 Views
Last Modified: 2012-05-10
I am trying to add the contents of a bunch of text boxes to get a total. There are 24 text boxes, and the code is attached.

My problem is that the Total is adding up to 500000 when I only put a 5 in one of the boxes. The text value for that box shows correctly in debug, but the total is adding all kinds of zeroes.

NZ is a user defined function that converts all of the boxes with nothing in them to zero.

What am I doing wrong?
Private Sub ResetAfterEntry()
        Dim dblRevenueTotal As Double

        dblRevenueTotal = CDbl(NZ((Me.txtJanCY.Text))) + CDbl(NZ((Me.txtFebCY.Text))) & _
            +CDbl(NZ((Me.txtMarCY.Text))) + CDbl(NZ((Me.txtAprCY.Text))) + CDbl(NZ((Me.txtMayCY.Text))) & _
            +CDbl(NZ((Me.txtJunCY.Text))) + CDbl(NZ((Me.txtJulCY.Text))) + CDbl(NZ((Me.txtAugCY.Text))) & _
            +CDbl(NZ((Me.txtSepCY.Text))) + CDbl(NZ((Me.txtOctCY.Text))) + CDbl(NZ((Me.txtNovCY.Text))) & _
            +CDbl(NZ((Me.txtDecCY.Text))) + CDbl(NZ((Me.txtJanNY.Text))) + CDbl(NZ((Me.txtFebNY.Text))) & _
            +CDbl(NZ((Me.txtMarNY.Text))) + CDbl(NZ((Me.txtAprNY.Text))) + CDbl(NZ((Me.txtMayNY.Text))) & _
            +CDbl(NZ((Me.txtJunNY.Text))) + CDbl(NZ((Me.txtJulNY.Text))) + CDbl(NZ((Me.txtAugNY.Text))) & _
            +CDbl(NZ((Me.txtSepNY.Text))) + CDbl(NZ((Me.txtOctNY.Text))) + CDbl(NZ((Me.txtNovNY.Text))) & _
            +CDbl(NZ((Me.txtDecNY.Text)))

        Me.txtTotalCurrentRevenue.Text = FormatCurrency(dblRevenueTotal, 2)
    End Sub

Open in new window

0
Comment
Question by:Buck_Beasom
2 Comments
 
LVL 19

Accepted Solution

by:
Bardobrave earned 500 total points
ID: 34196354
Maybe the "&" concatenation in your line are messing things up making your system to think that the whole result must be a string, making 5 + 0 = 50 in some cases.

Try to enclose in parenthesis every + operations in each line to avoid this type of confusions
0
 

Author Closing Comment

by:Buck_Beasom
ID: 34196912
I couldn't figure out where to put the parens, so I just removed the line breaks. It's a pain in the neck to look at the row - which is about a mile long - but it worked!

Thanks.
0

Featured Post

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

820 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