Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.basic.realbasic > #5

Re: Remove duplicate from ListBox

From "Auric__" <not.my.real@email.address>
Newsgroups comp.lang.basic.realbasic
Subject Re: Remove duplicate from ListBox
Date 2012-05-27 21:41 +0000
Organization A noiseless patient Spider
Message-ID <XnsA06095942D43Eauricauricauricauric@88.198.244.100> (permalink)
References <4fc21f6f$0$1762$c3e8da3$92d0a893@news.astraweb.com>

Show all headers | View raw


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

-- 
- Can we talk about this next week?
  - Just one more thing...
- Is it next week already?!

Back to comp.lang.basic.realbasic | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

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