7 * 24 * 60 * 60 = OverFlow !? 
Author Message
 7 * 24 * 60 * 60 = OverFlow !?

Run the following code in VB6, which causes an overflow error.

Dim x As Long                   'Same if long, double, integer, variant...
x = 7 * 24 * 60 * 60            'Causes overflow.
msgbox x                            'Should show 604800.

Does anyone have any insight/comments on this issue.  It seems a bit odd
that this can't be calculated without error.

Thanks in advance,



Sat, 27 Sep 2003 21:21:02 GMT  
 7 * 24 * 60 * 60 = OverFlow !?
A Long is not that big


Quote:
> Run the following code in VB6, which causes an overflow error.

> Dim x As Long                   'Same if long, double, integer, variant...
> x = 7 * 24 * 60 * 60            'Causes overflow.
> msgbox x                            'Should show 604800.

> Does anyone have any insight/comments on this issue.  It seems a bit odd
> that this can't be calculated without error.

> Thanks in advance,




Sat, 27 Sep 2003 21:33:31 GMT  
 7 * 24 * 60 * 60 = OverFlow !?
Hi Antoine,

VB is trying to calculate 7 * 24 * 60 * 60 in full before assigning it
to your variable. Since all of the composite parts of the calculation
are integers, it will try to assign the result of the calculation to an
internal temporary integer variable. This is what is overflowing. If you
force one of the parts of the calculation to be a long then the overflow
will not occur: x = clng(7) * 24 * 60 * 60

Rob

Quote:
> -----Original Message-----

> Posted At: 10 April 2001 14:21
> Posted To: microsoft.public.vb.com
> Conversation: 7 * 24 * 60 * 60 = OverFlow !?
> Subject: 7 * 24 * 60 * 60 = OverFlow !?

> Run the following code in VB6, which causes an overflow error.

> Dim x As Long                   'Same if long, double,
> integer, variant...
> x = 7 * 24 * 60 * 60            'Causes overflow.
> msgbox x                            'Should show 604800.

> Does anyone have any insight/comments on this issue.  It
> seems a bit odd
> that this can't be calculated without error.

> Thanks in advance,




Sat, 27 Sep 2003 21:37:28 GMT  
 7 * 24 * 60 * 60 = OverFlow !?
or
x = 7& * 24& * 60& * 60&
--
Session management for webfarms:
http://www.nieropwebconsult.nl/asp_session_manager.htm
"


Sun, 28 Sep 2003 21:06:30 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Why does 24*60*60 = overflow ?

2. CInt(60) * 1000 produces overflow?

3. Filesize to 60% by /decompile

4. LOOKUP BOX > 60 OBJECTS-NO SCROLL

5. Error 800a0011 - CommonDialog 60 on Excel user form

6. Visual Studio Net 60 Day Trial DVD

7. Ann: Zeus Programmers Editor V3.60

8. Ann: Zeus Programmers Editor V3.60

9. Re - Crystal reports(V4.60) problem in Client/server App

10. Sleep API is using up 60% CPU time in the DLL

11. Adding the numbers 1 - 60 to a combobox.....

12. Visual basic 60 service pack 4

 

 
Powered by phpBB® Forum Software