Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Overflow puzzle

Hi all,

My VBA editor returns a Run time overflow error for 300*8520000
but calculates without any fuss
2556*10^6
Yet both figures are the same viz: 2556000000
The same editor has no problem evaluating 2556*10^300

What gives?


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Overflow puzzle

? 252*8520000
2147040000
works, but 253*8520000
doesn't because it exceeds the maximum size of a long

? 300#*8520000
2556000000

works because it forces conversion to Double

2556*10^6

does the same for the same reason.

That would be my guess.

--
Regards,
Tom Ogilvy


"David Myle" wrote in message
...
Hi all,

My VBA editor returns a Run time overflow error for 300*8520000
but calculates without any fuss
2556*10^6
Yet both figures are the same viz: 2556000000
The same editor has no problem evaluating 2556*10^300

What gives?




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Overflow puzzle

When both operands are long, the return data type of the * operator is
Long. Both your operands fit within the Max Long, but the result of the
multiplication doesn't, hence the overflow.

The ^ operator returns a double, which will coerce the result to a
double, and the return data type of the * operator will be a Double.

You could make the first work by making one or the other operand a
double, e.g.,

300#*8520000

or

300*8520000#


In article ,
"David Myle" wrote:

Hi all,

My VBA editor returns a Run time overflow error for 300*8520000
but calculates without any fuss
2556*10^6
Yet both figures are the same viz: 2556000000
The same editor has no problem evaluating 2556*10^300

What gives?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Overflow puzzle

Hi Tom,

Still stumped because the following generates same overflow error. You
would imagine the declaration will fix the problem.

Sub test()
Dim x As Double
x = 253 * 8520000
MsgBox x
End Sub

"Tom Ogilvy" wrote in message
...
? 252*8520000
2147040000
works, but 253*8520000
doesn't because it exceeds the maximum size of a long

? 300#*8520000
2556000000

works because it forces conversion to Double

2556*10^6

does the same for the same reason.

That would be my guess.

--
Regards,
Tom Ogilvy


"David Myle" wrote in message
...
Hi all,

My VBA editor returns a Run time overflow error for 300*8520000
but calculates without any fuss
2556*10^6
Yet both figures are the same viz: 2556000000
The same editor has no problem evaluating 2556*10^300

What gives?






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Overflow puzzle

That doesn't force the calculate to be performed as double - just the
results, but the error has already occured.

Sub test()
Dim x As Double
x = 253# * 8520000
MsgBox x
End Sub



--
Regards,
Tom Ogilvy

"David Myle" wrote in message
...
Hi Tom,

Still stumped because the following generates same overflow error. You
would imagine the declaration will fix the problem.

Sub test()
Dim x As Double
x = 253 * 8520000
MsgBox x
End Sub

"Tom Ogilvy" wrote in message
...
? 252*8520000
2147040000
works, but 253*8520000
doesn't because it exceeds the maximum size of a long

? 300#*8520000
2556000000

works because it forces conversion to Double

2556*10^6

does the same for the same reason.

That would be my guess.

--
Regards,
Tom Ogilvy


"David Myle" wrote in message
...
Hi all,

My VBA editor returns a Run time overflow error for 300*8520000
but calculates without any fuss
2556*10^6
Yet both figures are the same viz: 2556000000
The same editor has no problem evaluating 2556*10^300

What gives?










  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Overflow puzzle

Your diagnosis and solution are spot on! As a check, a SINGLE coercion of
x = 253! * 8520000 also rides the error. Many thanks

DM

"Tom Ogilvy" wrote in message
...
That doesn't force the calculate to be performed as double - just the
results, but the error has already occured.

Sub test()
Dim x As Double
x = 253# * 8520000
MsgBox x
End Sub



--
Regards,
Tom Ogilvy

"David Myle" wrote in message
...
Hi Tom,

Still stumped because the following generates same overflow error. You
would imagine the declaration will fix the problem.

Sub test()
Dim x As Double
x = 253 * 8520000
MsgBox x
End Sub

"Tom Ogilvy" wrote in message
...
? 252*8520000
2147040000
works, but 253*8520000
doesn't because it exceeds the maximum size of a long

? 300#*8520000
2556000000

works because it forces conversion to Double

2556*10^6

does the same for the same reason.

That would be my guess.

--
Regards,
Tom Ogilvy


"David Myle" wrote in message
...
Hi all,

My VBA editor returns a Run time overflow error for 300*8520000
but calculates without any fuss
2556*10^6
Yet both figures are the same viz: 2556000000
The same editor has no problem evaluating 2556*10^300

What gives?










  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,071
Default Overflow puzzle

You have already received answers that work, but for those of us who
are not as up to speed with type-declaration-characters {g}, consider
x = CDbl(253) * 8520000
'above double coercion needed to avoid Long overflow error

--
Regards,

Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions

In article ,
says...
Hi all,

My VBA editor returns a Run time overflow error for 300*8520000
but calculates without any fuss
2556*10^6
Yet both figures are the same viz: 2556000000
The same editor has no problem evaluating 2556*10^300

What gives?



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
vlookup puzzle lloyd Excel Worksheet Functions 3 December 6th 07 07:45 PM
VLOOKUP puzzle ?? Anthony Excel Worksheet Functions 8 November 29th 06 05:49 PM
Can you help!!!!! New Puzzle Krefty Excel Discussion (Misc queries) 0 June 13th 05 08:13 PM
VBA overflow Tom Ogilvy Excel Programming 3 September 2nd 03 09:04 PM
VBA overflow Don Guillett[_4_] Excel Programming 2 September 2nd 03 04:19 PM


All times are GMT +1. The time now is 04:55 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"