DeltaWolf7
Well-known member
- Joined
- Jan 21, 2006
- Messages
- 47
- Programming Experience
- Beginner
I have written this code which does work, meaning no erros, but i dont have the knowlege to work out where it does not remove duplicates from my list.
Please can someone help me out?
Please can someone help me out?
VB.NET:
[SIZE=2][COLOR=#008000]' Check for Duplicates
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] itemsArray() [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String
[/COLOR][/SIZE][SIZE=2][COLOR=#008000]' get number of items in list.
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] ItemCount [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Integer[/COLOR][/SIZE][SIZE=2] = lstBox.Items.Count - 1
[/SIZE][SIZE=2][COLOR=#008000]' initilize array with slots for all items in list.
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]ReDim[/COLOR][/SIZE][SIZE=2] itemsArray(ItemCount)
[/SIZE][SIZE=2][COLOR=#008000]' create a variable to hold the position in the array to place the next item.
[/COLOR][/SIZE][SIZE=2][COLOR=#008000]' starts at position 1 because 0 will be filled with data on line after.
[/COLOR][/SIZE][SIZE=2][COLOR=#008000]'Dim NextIndex As Integer = 1
[/COLOR][/SIZE][SIZE=2][COLOR=#008000]' this is the data filled in to the array at pos 0.
[/COLOR][/SIZE][SIZE=2][COLOR=#008000]'itemsArray(0) = lstBox.Items.Item(ItemCount).ToString
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]For[/COLOR][/SIZE][SIZE=2] i [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Integer[/COLOR][/SIZE][SIZE=2] = 0 [/SIZE][SIZE=2][COLOR=#0000ff]To[/COLOR][/SIZE][SIZE=2] ItemCount
Debug.WriteLine([/SIZE][SIZE=2][COLOR=#800000]"i: "[/COLOR][/SIZE][SIZE=2] & i)
itemsArray(i) = lstBox.Items.Item(i).ToString
[/SIZE][SIZE=2][COLOR=#0000ff]For[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Each[/COLOR][/SIZE][SIZE=2] item [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]String[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]In[/COLOR][/SIZE][SIZE=2] itemsArray
Debug.WriteLine([/SIZE][SIZE=2][COLOR=#800000]"item: "[/COLOR][/SIZE][SIZE=2] & item)
[/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] itemsArray.IndexOf(itemsArray, item) <> i [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If[/COLOR][/SIZE][SIZE=2] item = lstBox.Items.Item(ItemCount).ToString [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2]Debug.WriteLine([/SIZE][SIZE=2][COLOR=#800000]"lstbox: "[/COLOR][/SIZE][SIZE=2] & lstBox.Items.Item(i))
lstBox.Items.RemoveAt(i)
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Next
[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Next
[/COLOR][/SIZE]