Solved

OverFlow Error

Posted on 2006-06-15
10
193 Views
Last Modified: 2010-04-30
I need to store decimal point values in a variable, the range of values is 19.999999 to 0.999999...

The problem is what type do I declare my variable as because....

Integer and Long no good as it rounds decimal places...

Decimal has a range of "For numbers with 28 decimal places, the range is
+/-7.9228162514264337593543950335. The smallest possible non-zero number is 0.0000000000000000000000000001."

Single has a range of "-3.402823E38 to -1.401298E-45 for negative values; 1.401298E-45 to 3.402823E38 for positive values."
 
Variant is the same as "Same range as Double for numerics."  

Thanks Ian

0
Comment
Question by:ISC
  • 4
  • 2
  • 2
  • +1
10 Comments
 
LVL 76

Expert Comment

by:GrahamSkan
Comment Utility
You can store the numbers 19.999999 to 0.999999... in doubles. How many significant digits (how accurate) do you need?
0
 
LVL 1

Author Comment

by:ISC
Comment Utility
At least 2 significant digits and 6 decimal places...

I tried this but I get an overflow error...


Ian
0
 
LVL 1

Author Comment

by:ISC
Comment Utility
The calculation causing the problem ss...

   Dim k As Double
       
    k = m_objAccrualRecord.m_intNumberOfDays * 100 * l_dblDailyAccrualTotal

This caused an overflow, however if I change the code to...

  Dim k As Double
       
        k = CDbl(m_objAccrualRecord.m_intNumberOfDays) * CDbl(100) * l_dblDailyAccrualTotal

It works....!
0
 
LVL 76

Expert Comment

by:GrahamSkan
Comment Utility
There is a buglet in VB. The calculation can start off assuming (for speed) that it is using integers, only to be confounded later on by a number too big to fit into its temporary location.
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 1

Author Comment

by:ISC
Comment Utility
Thanks I did not know that...!
0
 
LVL 26

Expert Comment

by:EDDYKT
Comment Utility
how about


k = l_dblDailyAccrualTotal * 100.0 * m_objAccrualRecord.m_intNumberOfDays
0
 
LVL 26

Expert Comment

by:EDDYKT
Comment Utility
or


k = m_objAccrualRecord.m_intNumberOfDays * 100.0 * l_dblDailyAccrualTotal
0
 
LVL 1

Author Comment

by:ISC
Comment Utility
My solution was to use CDbl( ) in the formula this worked and stopped the overflow error...!

 Dim k As Double
       
        k = CDbl(m_objAccrualRecord.m_intNumberOfDays) * CDbl(100) * l_dblDailyAccrualTotal
0
 

Accepted Solution

by:
RomMod earned 0 total points
Comment Utility
Question closed - 500 points refunded.

Best regards,
RomMod
Experts Exchange
Community Support Moderator
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

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…
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 Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
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…

744 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

15 Experts available now in Live!

Get 1:1 Help Now