Solved

Problem Converting Double

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

803 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