Le 31 janv. 09 à 20:10 (soir), Tom Russell a écrit:
I am trying to remove duplicates in an array but not sure how to
handle once I get down to below 0. TheDocs is an array of strings.
My code:
dim i as Integer
TheDocs.Sort
for i = UBound(TheDocs) downto 0
if TheDocs(i) = TheDocs(i-1) then
TheDocs.Remove i
end if
Next
Once i gets to 0 then it will throw an out of bounds exception and
this is where I am not sure how to handle this.
The problem here is that you don't need to compare from UBound to 0,
but from UBound to 1 (indeed, the 1st element will be compared to the
0th one at the end of your loop). So change 0 by 1.
Also, note that your code only removes subsequent duplicates (if the
5th item is the same as the 7th, your code will not remove one).
_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>
Search the archives:
<http://support.realsoftware.com/listarchives/lists.html>
|