Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 921
Default Overflow error when declaring variables

Hi,

When I declare the variable I get an overflow error -
depending on how it is declared.

Public IFundTable()

then in
Sub Macro1()
Redim IFundTable(1 to 5, 1 to 158510) 'There is no overflow error
Redim IFundTable(1 to 5, 1 to Count*10) 'Count = 15851, there is an error

Why?

Thanks for your help

  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 4,624
Default Overflow error when declaring variables

How did you declare Count?

If as a Variant or Integer, then that's the cause.

When you do math on variables or constants, the compiler tries to fit
the result into the longest operand type. Since both 10 and 15851 fit
within the Integer type, the result is expected to be an Integer.
Unfortunately, the result doesn't fit within the Integer type so you get
the overflow.

Try:

Public Sub Macro1()
Dim Count As Long
Count = 15851
ReDim IFundTable(1 To 5, 1 To 158510) 'There is no overflow error
ReDim IFundTable(1 To 5, 1 To Count * 10)
End Sub

Alternatively, declare the 10 to be of type Long

ReDim IFundTable(1 To 5, 1 To Count * 10#)

In article ,
Jeff wrote:

Hi,

When I declare the variable I get an overflow error -
depending on how it is declared.

Public IFundTable()

then in
Sub Macro1()
Redim IFundTable(1 to 5, 1 to 158510) 'There is no overflow error
Redim IFundTable(1 to 5, 1 to Count*10) 'Count = 15851, there is an error

Why?

Thanks for your help

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 921
Default Overflow error when declaring variables

Yes that was the problem - I declared count as an integer - when it is a
double there is no problem.

Thanks

"JE McGimpsey" wrote:

How did you declare Count?

If as a Variant or Integer, then that's the cause.

When you do math on variables or constants, the compiler tries to fit
the result into the longest operand type. Since both 10 and 15851 fit
within the Integer type, the result is expected to be an Integer.
Unfortunately, the result doesn't fit within the Integer type so you get
the overflow.

Try:

Public Sub Macro1()
Dim Count As Long
Count = 15851
ReDim IFundTable(1 To 5, 1 To 158510) 'There is no overflow error
ReDim IFundTable(1 To 5, 1 To Count * 10)
End Sub

Alternatively, declare the 10 to be of type Long

ReDim IFundTable(1 To 5, 1 To Count * 10#)

In article ,
Jeff wrote:

Hi,

When I declare the variable I get an overflow error -
depending on how it is declared.

Public IFundTable()

then in
Sub Macro1()
Redim IFundTable(1 to 5, 1 to 158510) 'There is no overflow error
Redim IFundTable(1 to 5, 1 to Count*10) 'Count = 15851, there is an error

Why?

Thanks for your help


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
Declaring variables in Module vs. Public Jeff Excel Discussion (Misc queries) 5 November 19th 07 08:27 PM
Overflow error.. why? Fingerjob Excel Discussion (Misc queries) 4 November 13th 06 05:18 PM
Declaring variables freekrill Excel Discussion (Misc queries) 2 July 19th 06 06:36 AM
Declaring variables freekrill Excel Discussion (Misc queries) 0 July 18th 06 06:15 PM
Overflow Error DG Excel Discussion (Misc queries) 3 April 15th 05 05:45 PM


All times are GMT +1. The time now is 03:49 AM.

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"