• Welcome to Valhalla Legends Archive.
 

?out of bounds

Started by blinkdude, December 02, 2003, 03:35 AM

Previous topic - Next topic

blinkdude

//checks to see if Username is in listview and if it is it deletes it, i get a Index out of bounds error sometimes ? ideas?


For X = 1 To Form1.lstls.ListItems.Count
 If Form1.lstls.ListItems.Item(X).Text = Username Then
   Form1.lstls.ListItems.Remove X
 End If
Next X
<Total-Assault@Azeroth> WTF IS THIS CLAN A BUNCH OF NERDS?
<Yoni[vL]@Azeroth> Yes.
<Grok> Yes.
<[vL]Kp> You sound surprised.
<Total-Assault> at least they admit it
&

DEAD


lstls.ListItems.Remove lstls.ListItems(x).Index

______

Quote from: blinkdude on December 02, 2003, 03:35 AM
//checks to see if Username is in listview and if it is it deletes it, i get a Index out of bounds error sometimes ? ideas?


For X = 1 To Form1.lstls.ListItems.Count
 If Form1.lstls.ListItems.Item(X).Text = Username Then
   Form1.lstls.ListItems.Remove X
 End If
Next X



Lets say you had five users in your listview, and you remove one the code you show is still checking the amount before you removed the user. so its still checking 5 instead of 4.
Maybe this will help?

For i = 1 To Form1.lstls.ListItems.Count
If username = Form1.lstls.ListItems(i).Text Then
Form1.lstls.ListItems.Remove Form1.lstls.FindItem(username).Index
Exit For
End If
Next i



blinkdude

<Total-Assault@Azeroth> WTF IS THIS CLAN A BUNCH OF NERDS?
<Yoni[vL]@Azeroth> Yes.
<Grok> Yes.
<[vL]Kp> You sound surprised.
<Total-Assault> at least they admit it
&

MyndFyre

In the future, you might want to post this question on the Visual Basic forum, as it really has nothing to do (except perhaps with your own project) with Battle.net bot development.
QuoteEvery generation of humans believed it had all the answers it needed, except for a few mysteries they assumed would be solved at any moment. And they all believed their ancestors were simplistic and deluded. What are the odds that you are the first generation of humans who will understand reality?

After 3 years, it's on the horizon.  The new JinxBot, and BN#, the managed Battle.net Client library.

Quote from: chyea on January 16, 2009, 05:05 PM
You've just located global warming.

ObsidianWolf

or perhaps one could search the forum for listbox or listview?  I know there is tons of example on removing items in listboxes(well maybe only more then 10 examples, but still).


Puzzle

I always use GoTo or Exit Sub when I am removing an item from a listview within a  loop.

Grok

Quote from: Puzzle on December 03, 2003, 12:16 PM
I always use GoTo or Exit Sub when I am removing an item from a listview within a  loop.

Why?  Give an example.

Spht

It sounds like you're all searching through the list in forward order without fixing your loop index after you remove an item, which is causing it to go out of bounds when you reach the last item.

I suggest either fixing your index after removing an item (i = i - 1) or search through the list in reverse order so that the removed indexes don't interfere with your search.

Puzzle

Quote from: Grok on December 03, 2003, 12:32 PM
Quote from: Puzzle on December 03, 2003, 12:16 PM
I always use GoTo or Exit Sub when I am removing an item from a listview within a  loop.

Why?  Give an example.

Continueing the loop = wasted CPU cycles.

Grok

Quote from: Puzzle on December 03, 2003, 02:35 PM
Quote from: Grok on December 03, 2003, 12:32 PM
Quote from: Puzzle on December 03, 2003, 12:16 PM
I always use GoTo or Exit Sub when I am removing an item from a listview within a  loop.

Why?  Give an example.

Continueing the loop = wasted CPU cycles.

Give a code example.

Spht

Quote from: Puzzle on December 03, 2003, 02:35 PM
Quote from: Grok on December 03, 2003, 12:32 PM
Quote from: Puzzle on December 03, 2003, 12:16 PM
I always use GoTo or Exit Sub when I am removing an item from a listview within a  loop.

Why?  Give an example.

Continueing the loop = wasted CPU cycles.

Not when continuing the loop is necessary for complete accuracy (there may be more than one matching item which you need to remove).

Adron

Quote from: Puzzle on December 03, 2003, 12:16 PM
I always use GoTo or Exit Sub when I am removing an item from a listview within a  loop.

Why do you never use Exit Do or Exit For?