The error message couldn't do a better job in conveying what went wrong. Lets back up...
An index is an integer that identifies the location of an element in a array, list, or other collection type. When accessing items in an array, list or other collection type, you use parenthesis with an index number inside. Array(Index# or Integer Variable).
Inclusive Lower Bound The Lower Bound is the lowest available index number in the collection, and should always be zero. There will not be a zero index in the collection if there are no items in the collection. Inclusive Upper Bound The Upper Bound is the highest available index number in the collection. What do you mean by Inclusive? This means that this number is included in the range.
Remember, this error message does an excellent job of conveying what went wrong and what to avoid! It tells you:
How to avoid this error:
Option
Strict
On
Public
Class
Form1
Private
Sub
Button1_Click(
ByVal
sender
As
System.
Object
,
e
System.EventArgs)
Handles
Button1.Click
Dim
MyArray
Integer
() = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
Tmp
For
I = 0
To
UBound(MyArray)
'This will not go outside of the bounds of the array
'no error will be caught here
Try
Tmp = MyArray(I)
Catch
ex
Exception
MsgBox(ex.Message)
End
Next
MyArray.Count - 1
9
MyArray.Count
'This will go outside of the bounds of the array
'and an error will be caught
10
I hope you find this helpful, and if I have missed something, please update the article!