I couldn't understand what you mean by "List". "
List(Of T)
" or "
ListBox
" or something else...
So I will give a general answer.
When you remove an item from a list, item count of this list decreases. This is why fixed loops don't work as expected. I wrote a method below that removes duplicated items in a ListBox object. You can adapt this method to your purpose...
Private Sub RemoveDupItems(ByRef ListBoxObj As ListBox)
Dim ItemCount As Integer = ListBoxObj.Items.Count
Dim Position1 As Integer = 0
While (Position1 < ItemCount)
Dim Position2 As Integer = 0
While (Position2 < ItemCount)
If Position1 <> Position2 Then
If ListBoxObj.Items(Position1) = ListBoxObj.Items(Position2) Then
ListBoxObj.Items.RemoveAt(Position2)
ItemCount -= 1
Exit While
End If
End If
Position2 += 1
End While
Position1 += 1
End While
End Sub
Usage example:
RemoveDupItems(ListBox1)