PDA

Click to See Complete Forum and Search --> : variable overflow in VBA


vb_student
Jul 6th, 2006, 05:10 AM
Hello

I was wondering what happened to the execution of a program after a variable overflows. does the program continue right after the code which does the overflow or is the execution indeterminate.

i have got this piece of code which seems to run of to the begining of the loop (where the offending piece of code was within the loop)

also in vba is there any way to ifnd out if a variable has overflown by using a breakpoint.

Dnereb
Jul 6th, 2006, 05:32 AM
What happens on a overflow depends on your error handling
3 Examples, Normal, with error handling and the worst ignoring any errorsSub test1()

Dim I As Integer

For I = 32760 To 32768

Next

End Sub

Sub test2()

Dim I As Integer

On Error GoTo test2_Error

For I = 32760 To 32768

Next

On Error GoTo 0
Exit Sub

test2_Error:

MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure test2 of Module Module1"

End Sub

Sub test3()

Dim I As Integer
On Error Resume Next 'this will ignore the error and continue
For I = 32760 To 32768

Next

End Sub

Now with a nice errorhandler

vb_student
Jul 6th, 2006, 02:37 PM
thanks for the reply

i guess without the error handler, the behaviour is indeterminate, correct?

RobDog888
Jul 6th, 2006, 03:05 PM
If the variable overflows you will generate an error. Just trap for that error. Best thing to do i=s to dimension your variables with the proper type and size.

vb_student
Jul 16th, 2006, 01:45 PM
thanks for the reply robdog

what kind of error will the variable overflow generate?

how does one trap for that error?

what is i=s?

salvelinus
Jul 16th, 2006, 02:34 PM
Well, create the overflow and see what the error number is. Then trap for that in your error handler (If err.Number = 5614 then... and no, I don't know what the correct error number is, 5614 is an example).
i=s is probably a typo for is, as in "Best thing to do is..." ;)

vb_student
Jul 16th, 2006, 06:03 PM
thanks for the reply

there were overflows within my program, but the program just seemed to go in a loop and did not give any errors