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

Excel 2003 SP2





Hello every body


This little sub gives me a runtime overflow. Did I miss something?




Sub ebj()

Dim ll_test As Long

ll_test = 162 * 207


End Sub



I would have expected ll_test to take a value = 33,534. A Long should be
sufficient to hold that. If I change the declaration to Single or Variant I
still get an overflow.



Any suggestions?





Best regards

Erik




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 225
Default Overflow

The problem is that VBA tries to calculate
162 * 207 as an Integer, and then convert
to the result to a Long. The first of these
steps causes the overflow. You can get
round this by forcing one of the values
to be a Long:

ll_test = 162& * 207
or
ll_test = CLng(162) * 207

Note that ll_test = clng(162 * 207) will fail,
for the same reason as in the original problem.


Andrew Taylor




Erik Beck Jensen wrote:
Excel 2003 SP2

Hello every body


This little sub gives me a runtime overflow. Did I miss something?




Sub ebj()

Dim ll_test As Long

ll_test = 162 * 207


End Sub



I would have expected ll_test to take a value = 33,534. A Long should be
sufficient to hold that. If I change the declaration to Single or Variant I
still get an overflow.



Any suggestions?





Best regards

Erik


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

Thanks you very much.

The problem is solved.



Best regards

Erik





"Andrew Taylor" wrote in message
oups.com...
The problem is that VBA tries to calculate
162 * 207 as an Integer, and then convert
to the result to a Long. The first of these
steps causes the overflow. You can get
round this by forcing one of the values
to be a Long:

ll_test = 162& * 207
or
ll_test = CLng(162) * 207

Note that ll_test = clng(162 * 207) will fail,
for the same reason as in the original problem.


Andrew Taylor




Erik Beck Jensen wrote:
Excel 2003 SP2

Hello every body


This little sub gives me a runtime overflow. Did I miss something?




Sub ebj()

Dim ll_test As Long

ll_test = 162 * 207


End Sub



I would have expected ll_test to take a value = 33,534. A Long should be
sufficient to hold that. If I change the declaration to Single or Variant
I
still get an overflow.



Any suggestions?





Best regards

Erik




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
overflow error ExcelMonkey[_5_] Excel Programming 6 January 22nd 04 02:34 AM
buffer overflow Jeff Sward Excel Programming 0 January 7th 04 07:46 PM
Overflow in VBA, but value < limit Brad[_13_] Excel Programming 3 December 11th 03 04:16 AM
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 09:40 PM.

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

About Us

"It's about Microsoft Excel"