• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

VBScript Array question

jonmullen

Platinum Member
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?
 
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.
 
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.
 
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.
 
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)



 
Back
Top