Solved

Subtraction using double

Posted on 2004-04-29
4
200 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
ID: 10952137
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
ID: 10952161
HI FTIISD,
    Did you try to use the function cdbl() insteadof val() or not ? I think it might be better ...
                                                                   Meng
0
 
LVL 50

Accepted Solution

by:
Ryan Chong earned 300 total points
ID: 10952178
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
ID: 10952274
Was able to get it working with CCur()

Thanks for the help!
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…

773 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