[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 144
  • Last Modified:

(50 pts) Error 6 - Overflow

I'm designing a program that will calculate the number of Miliseconds in a Millenium and everything in between.  As  you can tell, I need a way to store and work with VERY large numbers.  I tried using Double and it's giving the a Run-Time Error 6 - Overflow.  That shouldn't be happening especially since it gives it trying to store the value 60,000.  Here's my code.  PLEASE HELP !!


Public zConst_Time(12, 12) As Double

zConst_Time(3, 1) = 1000 * 60


It gives the error on this line.  What's going wrong?

HATCHET
0
HATCHET
Asked:
HATCHET
  • 2
1 Solution
 
mark2150Commented:
60 and 1000 are *integers*.

Write:

zConst_Time(3, 1) = 1000.0 * 60.0

and it will work.

m
0
 
HATCHETAuthor Commented:
mark2150,

Thanks for the help!  Your answer didn't work EXACTLY... but got me where I needed to go.  Visual Basic saw the extra ".0" at the end of the numbers and changed them to pound signs ( # ).

For some reason... if you put a pound sign, which is the Double data type indicator, at the end of the first number to be multiplied, it works.  I assume that once it hits that first pound sign it knows the rest of the values are Double as well.  Like this:

zConst_Time(1, 1) = 1000# * 60 * 60 * 24 * 7 * 4.345 * 3 * 4 * 1000

That returns the following value : 31534272000000

Thanks again !

HATCHET
0
 
mark2150Commented:
Vb is easy going about data types. It looks at the types on the right side of the assignment and computes the result in the "lowest" (shortest?) data type that all of the values have. Since all the values were INTEGERS it did integer math and 60000 is out of the integer range of +-32767 and *bang* you're dead. It didn't matter that the zConst_Time() array was defined as DOUBLE because the overflow occurred in an intermediate value as it was evaluating the right side of the assignment.

As long as *any* of the values on the right is non-integer it should work. The # sign is appended because .0 is technically "redundent", but it figured out that you wanted a *real* there instead of an integer and used the # to force the type. You could eliminate it in your example since you have 4.345 as one real in the series. This will force the intermediate result to a real and all is fine.

This is both a strength and weakness of VB. It allows you to write without worrying about typing, but occassionally, it rears it's head and *bites* you.

M
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now