Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 100
Default run-time error '6' - overflow - once I declare a pre-used variable name as integer

Excel 2003 on WinXP run-time error '6' - overflow

I'm writing more an more blocks of code on a program that is (or was) acting
as expected. I'm not a programmer by trade or training, so although I know I
should use option explicit on, it isn't one of the habits I've picked up
yet.

I often use a random variable name for loops, and often use the same
variable name in the same sub or in different subs. I'm just starting to
pass more and more information to functions, and I was having trouble with
Excel accepting the transferred parameters unless I declared the sending and
recieving variables explicitly (and the same, of course). One variable that
I need to pass to my function is my loop variable (it refers to a
position/location on a sheet or array).

So, since I use it as an integer in my function, I declared it as an integer
in my main sub. However, when it hits my loop, I now get a run-time error
'6' overflow. Can anyone explain why this happens, and the proper way to
effectively pass that loop variable as an integer to my function?

Many thanks,
Keith

'irrelevant code blocks deleted
Sub AssembleSchedule()

Dim EachDate As Date
Dim EachDay As Integer
'dim the other variables that are passed to my procedure

For EachDay = 1 To 50000 'error occurs here before looping begins;
'error did not occur here
before the dim
'but I had trouble passing
the data to the function
'do stuff
Next

For EachDay = 1 To 50000
'do other stuff
Next

For EachDay = 0 To 14
'do stuff for a target 2-week window of dates
Next

dummyvariable = BatchingSearch(BatchingDaysOut, EachDay,
RemainingCapacity, UseDept)

End sub

Function BatchingSearch(sDaysOut As Integer, sNowDate As Integer,
sRemainingCapacity As Long, CurrDept As String)
'do other stuff
End function




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 249
Default run-time error '6' - overflow - once I declare a pre-used variable name as integer

Try dimensioning as Long. An integer valid range is -32,768 to 32,767


--

Regards,

Dave Patrick ....Please no email replies - reply in newsgroup.
Microsoft Certified Professional
Microsoft MVP [Windows]
http://www.microsoft.com/protect

"ker_01" wrote:
Excel 2003 on WinXP run-time error '6' - overflow

I'm writing more an more blocks of code on a program that is (or was)
acting as expected. I'm not a programmer by trade or training, so although
I know I should use option explicit on, it isn't one of the habits I've
picked up yet.

I often use a random variable name for loops, and often use the same
variable name in the same sub or in different subs. I'm just starting to
pass more and more information to functions, and I was having trouble with
Excel accepting the transferred parameters unless I declared the sending
and recieving variables explicitly (and the same, of course). One variable
that I need to pass to my function is my loop variable (it refers to a
position/location on a sheet or array).

So, since I use it as an integer in my function, I declared it as an
integer in my main sub. However, when it hits my loop, I now get a
run-time error '6' overflow. Can anyone explain why this happens, and the
proper way to effectively pass that loop variable as an integer to my
function?

Many thanks,
Keith

'irrelevant code blocks deleted
Sub AssembleSchedule()

Dim EachDate As Date
Dim EachDay As Integer
'dim the other variables that are passed to my procedure

For EachDay = 1 To 50000 'error occurs here before looping begins;
'error did not occur here
before the dim
'but I had trouble passing
the data to the function
'do stuff
Next

For EachDay = 1 To 50000
'do other stuff
Next

For EachDay = 0 To 14
'do stuff for a target 2-week window of dates
Next

dummyvariable = BatchingSearch(BatchingDaysOut, EachDay,
RemainingCapacity, UseDept)

End sub

Function BatchingSearch(sDaysOut As Integer, sNowDate As Integer,
sRemainingCapacity As Long, CurrDept As String)
'do other stuff
End function





  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 915
Default run-time error '6' - overflow - once I declare a pre-used variablename as integer

ker_01 wrote:
Excel 2003 on WinXP run-time error '6' - overflow


[snipped]

'irrelevant code blocks deleted
Sub AssembleSchedule()

Dim EachDate As Date
Dim EachDay As Integer
'dim the other variables that are passed to my procedure

For EachDay = 1 To 50000 'error occurs here before looping begins;


ker,

Integer type values cannot exceed +/- 32767 or so. Try Dim EachDay as
Long, or restricting the loop to a range Integer can accept.

I did not follow your code much beyond here so something else may be amiss.
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 100
Default run-time error '6' - overflow - once I declare a pre-used variable name as integer

Doh! Thanks Dave and SMartin- I had made several changes and was eliminating
one potential cause at a time...and had forgotten about the integer
limitation. I'll change it to long, and I'm sure I'll have no problems.
Thanks!
Keith

"Dave Patrick" wrote in message
...
Try dimensioning as Long. An integer valid range is -32,768 to 32,767


--

Regards,

Dave Patrick ....Please no email replies - reply in newsgroup.
Microsoft Certified Professional
Microsoft MVP [Windows]
http://www.microsoft.com/protect

"ker_01" wrote:
Excel 2003 on WinXP run-time error '6' - overflow

I'm writing more an more blocks of code on a program that is (or was)
acting as expected. I'm not a programmer by trade or training, so
although I know I should use option explicit on, it isn't one of the
habits I've picked up yet.

I often use a random variable name for loops, and often use the same
variable name in the same sub or in different subs. I'm just starting to
pass more and more information to functions, and I was having trouble
with Excel accepting the transferred parameters unless I declared the
sending and recieving variables explicitly (and the same, of course). One
variable that I need to pass to my function is my loop variable (it
refers to a position/location on a sheet or array).

So, since I use it as an integer in my function, I declared it as an
integer in my main sub. However, when it hits my loop, I now get a
run-time error '6' overflow. Can anyone explain why this happens, and the
proper way to effectively pass that loop variable as an integer to my
function?

Many thanks,
Keith

'irrelevant code blocks deleted
Sub AssembleSchedule()

Dim EachDate As Date
Dim EachDay As Integer
'dim the other variables that are passed to my procedure

For EachDay = 1 To 50000 'error occurs here before looping begins;
'error did not occur here
before the dim
'but I had trouble passing
the data to the function
'do stuff
Next

For EachDay = 1 To 50000
'do other stuff
Next

For EachDay = 0 To 14
'do stuff for a target 2-week window of dates
Next

dummyvariable = BatchingSearch(BatchingDaysOut, EachDay,
RemainingCapacity, UseDept)

End sub

Function BatchingSearch(sDaysOut As Integer, sNowDate As Integer,
sRemainingCapacity As Long, CurrDept As String)
'do other stuff
End function







  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 249
Default run-time error '6' - overflow - once I declare a pre-used variable name as integer

You're welcome.


--

Regards,

Dave Patrick ....Please no email replies - reply in newsgroup.
Microsoft Certified Professional
Microsoft MVP [Windows]
http://www.microsoft.com/protect


"ker_01" wrote:
Doh! Thanks Dave and SMartin- I had made several changes and was
eliminating one potential cause at a time...and had forgotten about the
integer limitation. I'll change it to long, and I'm sure I'll have no
problems.
Thanks!
Keith


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
Run-Time error '91': Object variable of With block variable not set jammin1911 Excel Programming 3 June 6th 06 06:36 PM
Run-time error '91': "Object variable or With block variable not set Mike[_92_] Excel Programming 2 December 30th 04 10:59 AM
run-time error 6 - overflow Paul Excel Programming 1 November 11th 04 11:09 AM
Run-time error '6' overflow Suzy[_2_] Excel Programming 2 February 13th 04 04:55 PM
Run-time error 6 Overflow FredM Excel Programming 2 January 20th 04 06:05 AM


All times are GMT +1. The time now is 02:09 AM.

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"