K
ker_01
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
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