Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Problem Converting Double

Posted on 2010-11-23
2
Medium Priority
?
195 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 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

670 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