VBScript Array question

jonmullen

Platinum Member
Jun 17, 2002
2,517
0
0
Ok I have an array of members (arrMembers()) I want to take all dublicate records out of the array, how would I go about that?
 

bontu

Member
Jan 14, 2000
182
0
76
you could eliminate duplicates before hand by not entering it into the array in the first place if it already exists in there.

anyways you can have a 2nd array to hold the new data with no duplicates.
take the first element in 1st array and enter it into the 2nd.
take the 2nd element in 1st array and check contents of 2nd to ensure no duplicates before inserting.
repeat etc.
 

igowerf

Diamond Member
Jun 27, 2000
7,697
1
76
Maybe you can sort the array and remove any duplicates during the sort.

You should change your thread title to something more general like "Need help removing duplicate entries from array". Your question really isn't VB specific unless you're looking for a VB function that does this.
 

glugglug

Diamond Member
Jun 9, 2002
5,340
1
81
VB/VBscript array manipulation SUCKS performancewise, you want to minimize what operations you actually do with arrays.

So rather than making a second (sorted) array to check for duplicates in, loop through putting each element in a dictionary. When you come across an element that's already in the dictionary, that means it's a duplicate.
 

jonmullen

Platinum Member
Jun 17, 2002
2,517
0
0
Originally posted by: glugglug
VB/VBscript array manipulation SUCKS performancewise, you want to minimize what operations you actually do with arrays.

So rather than making a second (sorted) array to check for duplicates in, loop through putting each element in a dictionary. When you come across an element that's already in the dictionary, that means it's a duplicate.

Thanks guys this is how I ended up doing it. And yes VB support for arrays sucks.


Dim strDictionary
strDictionary = array(0) 'Puts someting in the dictionary so its not empty. I dont know if its required for instr to work
for each x in array
If Instr(array,x) = 0 then 'This check is the current array value is in the dictionary string 0 means no match
strDictionary = strDictionary & " " & x 'adds value to dictionary
end if
next

newarray = split(array)