Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.basic.realbasic > #6
| Date | 2012-06-02 11:31 +1000 |
|---|---|
| From | Liam Whan <liam.whan@gmail.com> |
| Newsgroups | comp.lang.basic.realbasic |
| Subject | Re: Remove duplicate from ListBox |
| References | <4fc21f6f$0$1762$c3e8da3$92d0a893@news.astraweb.com> <XnsA06095942D43Eauricauricauricauric@88.198.244.100> |
| Message-ID | <4fc96cfd$0$1747$c3e8da3$92d0a893@news.astraweb.com> (permalink) |
| Organization | Unlimited download news at news.astraweb.com |
On 28/05/2012 7:41 AM, Auric__ wrote: > Liam Whan wrote: > >> I'm sure this is easy to answer but I can not figureit out. >> >> I am getting an OutOfBoundException when I run this loop that loops >> through the listbox in question and looks for duplicate values. Could >> anyone shed any light on this? >> >> >> For intListCountF As integer = 0 to frmPlayer.Listbox1.ListCount -1 >> For intListCountB As Integer = frmPlayer.Listbox1.Listcount -1 to 0 >> Step -1 >> if frmplayer.Listbox1.List(intListCountB) = >> frmPlayer.Listbox1.List(intListCountF) Then >> frmplayer.Listbox1.RemoveRow(intListCountB) >> end if >> Next >> Next > You're clearing your list. When intListCountF has the same value as > intListCountB, you're removing the item. Since you will get to *every* value > in the list in both For loops, you will remove *everything*. Eventually > you're left with a list containing zero items. > > Try something like this (untested air code): > > For intListCountF As Integer = 0 To frmPlayer.Listbox1.ListCount - 2 > For intListCountB As Integer = frmPlayer.Listbox1.ListCount - 1 To _ > intListCountF + 1 Step -1 > If frmplayer.Listbox1.List(intListCountB) = _ > frmPlayer.Listbox1.List(intListCountF) Then > frmplayer.Listbox1.RemoveRow(intListCountB) > End If > Next > Next > Of Course! I'm an idiot! Thanks so much guys. what I eventually went with was an algorithim that -1 off the row count every time it removed a row. Thanks again! Liam
Back to comp.lang.basic.realbasic | Previous | Next — Previous in thread | Find similar
Remove duplicate from ListBox Liam Whan <liam.whan@gmail.com> - 2012-05-27 22:34 +1000
Re: Remove duplicate from ListBox Dale Arends <DaleSafe@sbcglobal.net> - 2012-05-27 16:20 -0500
Re: Remove duplicate from ListBox "Auric__" <not.my.real@email.address> - 2012-05-27 21:41 +0000
Re: Remove duplicate from ListBox Liam Whan <liam.whan@gmail.com> - 2012-06-02 11:31 +1000
csiph-web