• Welcome to Valhalla Legends Archive.
 

index out of bounds

Started by Acid~, February 10, 2003, 03:25 PM

Previous topic - Next topic

Acid~

I keep getting this,
Error: index out of bounds                       highlighted: ChannelList.ListItems.Remove (pos)

For everything ive tried, i cant fix it :-[

Spht

#1
Means you are trying to remove an item array that does not exist in the upper bounded range. The index that you are supposed to supply for Remove() is the index of the item in the list.

Mesiah / haiseM

#2
simple fix (not good, but it works)
add "On Error Resume Next" to the sub or function
]HighBrow Innovations
Coming soon...

AIM Online Status: 

Skywing

#3
Quotesimple fix (not good, but it works)
add "On Error Resume Next" to the sub or function
I may not be a Visual Basic programmer, but I can tell you that in general it's almost never a good idea to just ignore all errors.  They're there for a reason.

Mesiah / haiseM

#4
well this is true, but depending on the sub or function it may be alright to slap that in there, but if the sub or function contains many more things than just that, i wouldnt reccomend it. some errors will still appear with on error resume next, depending on theyre priority.
]HighBrow Innovations
Coming soon...

AIM Online Status: 

Zakath

#5
In the case of referencing an array element that doesn't exist: that's probably a bad idea, especially if "resuming next" would wind up having you calling on that element. In C++ arrays aren't necessarily initialized, and referencing an uninitialized array (i.e. an element that has no specific value) causes errors via attempting to read or write restricted memory addresses. In case you didn't already know, that causes a crash.
Quote from: iago on February 02, 2005, 03:07 PM
Yes, you can't have everybody...contributing to the main source repository.  That would be stupid and create chaos.

Opensource projects...would be dumb.

Acid~

#6
Well, your all wrong, since you cannot put that line in front on the sub, or in it.
 - I found the bug any way ;\, the cleanslatebot.ocx version i had, had a bug in it, where for the information it had a line from one of the earlier versions

Acid~

#7
Thx for you help anyway :)

Acid~

#8
Wait, or maybe putting that at the top of the source would enable it ;\

KBL_BlackIce

#9
On Error Resume Next can be put ANYWHERE, and it will have the scope of the place you put it.  For example:

Sub TestThis()
  On Error Resume Next
  
  Dim ayArray(12) as String

  MsgBox ayArray(13)
End Sub

This will simply pass over the erroneous MsgBox line, and continue processing (but not a good idea)

At the top of a code module/class module/form

Option Explicit
On Error Resume Next

<functions here>

This will make the statement global if in a code module, local to the form in a form, local to the class in a private, public or global class module.

Oh, and one more thing...

IT WORKS ANYWHERE


Skywing

#10
QuoteIn the case of referencing an array element that doesn't exist: that's probably a bad idea, especially if "resuming next" would wind up having you calling on that element. In C++ arrays aren't necessarily initialized, and referencing an uninitialized array (i.e. an element that has no specific value) causes errors via attempting to read or write restricted memory addresses. In case you didn't already know, that causes a crash.
Err.. If you follow your logic, you'd crash every time you tried to initialize an array.

Yoni

#11
QuoteAt the top of a code module/class module/form
I didn't think that works. Are you sure?

Spht

#12
QuoteI didn't think that works. Are you sure?

Not in the version of Visual Basic I have... Even if it did work, I wouldn't recommend it since you're ignoring all errors which could be a very bad thing if you're just developing a program.

Zakath

#13
QuoteErr.. If you follow your logic, you'd crash every time you tried to initialize an array.

I guess that was unclear. I meant that if you tried to do something with the value stored in an array element that was not initialized, the program would crash. Actually initializing it doesn't cause a crash, of course.
Quote from: iago on February 02, 2005, 03:07 PM
Yes, you can't have everybody...contributing to the main source repository.  That would be stupid and create chaos.

Opensource projects...would be dumb.

Yoni

#14
It wouldn't crash, it would just get a meaningless value.
(This can indirectly cause a crash, if that meaningless value is expected to be meaningful... But just reading it won't crash.)