Solved

Subtraction using double

Posted on 2004-04-29
4
198 Views
Last Modified: 2010-05-02
Hi,

Im am running the following code:
frmAddToFile.txtBalance = Val(frmAddToFile.adoFileInformation.Recordset.Fields("saleamount")) - Val(frmAddToFile.txtTotalPaidToDate) - Val(txtAmountPaying.Text)

where frmAddToFile.adoFileInformation.Recordset.Fields("saleamount") = 10707.49
and frmAddToFile.txtTotalPaidToDate = 8022.89
and txtAmountPaying.Text = 2684.60

this should compute to 0 but instead it = -4.54747350.......

I understand this has to do with the way it is stored in binary, but I need a way of making this work.

Thanks!
0
Comment
Question by:FTIISD
4 Comments
 
LVL 19

Assisted Solution

by:Shauli
Shauli earned 100 total points
Comment Utility
frmAddToFile.txtBalance = (Val(frmAddToFile.adoFileInformation.Recordset.Fields("saleamount")) - (Val(frmAddToFile.txtTotalPaidToDate) + Val(txtAmountPaying.Text))

S
0
 
LVL 6

Assisted Solution

by:prasitlee
prasitlee earned 100 total points
Comment Utility
HI FTIISD,
    Did you try to use the function cdbl() insteadof val() or not ? I think it might be better ...
                                                                   Meng
0
 
LVL 49

Accepted Solution

by:
Ryan Chong earned 300 total points
Comment Utility
Try:

frmAddToFile.txtBalance = Val(Val(frmAddToFile.adoFileInformation.Recordset.Fields("saleamount")) - Val(frmAddToFile.txtTotalPaidToDate)) - Val(txtAmountPaying.Text)

or is will be better if you use CCur function instead:

frmAddToFile.txtBalance = CCur(frmAddToFile.adoFileInformation.Recordset.Fields("saleamount")) - CCur(frmAddToFile.txtTotalPaidToDate) - CCur(txtAmountPaying.Text)
0
 

Author Comment

by:FTIISD
Comment Utility
Was able to get it working with CCur()

Thanks for the help!
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

743 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

16 Experts available now in Live!

Get 1:1 Help Now