Solved

Problem Converting Double

Posted on 2010-11-23
2
187 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
Comment Utility
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
Comment Utility
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 to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

772 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

13 Experts available now in Live!

Get 1:1 Help Now