Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: VB4,VB5,VB6
Expertise: Intermediate
Nov 20, 1999

HasDuplicateValues - Check if an array has duplicate values

' Returns True if an array contains duplicate values
' it works with arrays of any type

Function HasDuplicateValues(arr As Variant) As Boolean
    Dim col As Collection, index As Long
    Set col = New Collection
    
    ' assume that the array contains duplicates
    HasDuplicateValues = True
    
    On Error GoTo FoundDuplicates
    For index = LBound(arr) To UBound(arr)
        ' build the key using the array element
        ' an error occurs if the key already exists
        col.Add 0, CStr(arr(index))
    Next
    ' if control comes here, the array doesn't contain
    ' any duplicate values, so we can return zero
    HasDuplicateValues = False
    
FoundDuplicates:

End Function
Francesco Balena
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date