Solved

Problem Converting Double

Posted on 2010-11-23
2
191 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
[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
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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

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…
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decade…

759 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