3

I have some code along the lines of the following:

redim a(1 to N)
for i = 1 to N
    a(i) = someFunction(i)
Next i

When running it, I get "Run-time error 6: Overflow". And it enters break mode with the line inside the loop: a(i) = someFunction(i) highlighted. To find the error, I step into that function and step over line-by-line. There's no error, it works fine and keeps going. As long as I execute the code this way, staying in break mode & stepping in to someFunction one call at a time, it works, but as soon as I go back to normal execution, the overflow error comes back.

Does anyone know how can I get rid of the overflow?

3
  • What are the values for a(i), i and someFunction(i) at halt? Just move a mouse cursor over variable names in VBE. Commented Nov 9, 2012 at 17:36
  • are you moving through rows? Row counters should be declared as Long if you are Commented Nov 9, 2012 at 18:10
  • 1
    Yea I was gonna say, you probably aren't getting an overflow error because when you are debugging you aren't going all the way through the code. salih0vicX's answer is a probable cause of the problem. It would also explain why you aren't reproducing the error in debugging, because it would take 32,767 iterations before you found the overflow error. Commented Nov 9, 2012 at 18:17

2 Answers 2

1

You should provide whole function so we could see the way you declared variables.

The error is cause by wrong variable declaration. One or more of your variables has no capacity to accept the value (example: you declared variable i as Integer so it cannot accept the value like: i=55000; the maximum value for integer is somewhere around 32000 to 32800)...

Sign up to request clarification or add additional context in comments.

1 Comment

That magic number is 32767. Signed 16-bit integers range from -2^15 to 2^15-1.
0

Thanks everyone for helping, I figured out what the problem was. It was something in someFunction causing the overflow, I'm not sure why it didn't happen in break mode, but I fixed what was causing it and it's working now.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.