Author | Message | Time |
---|---|---|
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? [code] 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 [/code] | December 2, 2003, 9:35 AM |
DEAD | [code] lstls.ListItems.Remove lstls.ListItems(x).Index [/code][code][/code] | December 2, 2003, 12:26 PM |
______ | [quote author=blinkdude link=board=17;threadid=4019;start=0#msg33170 date=1070357753] //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? [code] 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 [/code] [/quote] 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? [code] 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 [/code] | December 2, 2003, 2:36 PM |
blinkdude | thanks works! | December 2, 2003, 8:56 PM |
Myndfyr | 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. | December 2, 2003, 9:39 PM |
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). | December 3, 2003, 4:35 AM |
Puzzle | I always use GoTo or Exit Sub when I am removing an item from a listview within a loop. | December 3, 2003, 6:16 PM |
Grok | [quote author=Puzzle link=board=31;threadid=4019;start=0#msg33423 date=1070475396] I always use GoTo or Exit Sub when I am removing an item from a listview within a loop. [/quote] Why? Give an example. | December 3, 2003, 6:32 PM |
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. | December 3, 2003, 7:35 PM |
Puzzle | [quote author=Grok link=board=31;threadid=4019;start=0#msg33428 date=1070476337] [quote author=Puzzle link=board=31;threadid=4019;start=0#msg33423 date=1070475396] I always use GoTo or Exit Sub when I am removing an item from a listview within a loop. [/quote] Why? Give an example. [/quote] Continueing the loop = wasted CPU cycles. | December 3, 2003, 8:35 PM |
Grok | [quote author=Puzzle link=board=31;threadid=4019;start=0#msg33457 date=1070483742] [quote author=Grok link=board=31;threadid=4019;start=0#msg33428 date=1070476337] [quote author=Puzzle link=board=31;threadid=4019;start=0#msg33423 date=1070475396] I always use GoTo or Exit Sub when I am removing an item from a listview within a loop. [/quote] Why? Give an example. [/quote] Continueing the loop = wasted CPU cycles. [/quote] Give a code example. | December 3, 2003, 8:48 PM |
Spht | [quote author=Puzzle link=board=31;threadid=4019;start=0#msg33457 date=1070483742] [quote author=Grok link=board=31;threadid=4019;start=0#msg33428 date=1070476337] [quote author=Puzzle link=board=31;threadid=4019;start=0#msg33423 date=1070475396] I always use GoTo or Exit Sub when I am removing an item from a listview within a loop. [/quote] Why? Give an example. [/quote] Continueing the loop = wasted CPU cycles. [/quote] Not when continuing the loop is necessary for complete accuracy (there may be more than one matching item which you need to remove). | December 3, 2003, 9:14 PM |
Adron | [quote author=Puzzle link=board=31;threadid=4019;start=0#msg33423 date=1070475396] I always use GoTo or Exit Sub when I am removing an item from a listview within a loop. [/quote] Why do you never use Exit Do or Exit For? | December 5, 2003, 9:55 AM |