Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX

By submitting your information, you agree that devx.com may send you DevX offers via email, phone and text message, as well as email offers about other products and services that DevX believes may be of interest to you. DevX will process your information in accordance with the Quinstreet Privacy Policy.

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



Application Security Testing: An Integral Part of DevOps

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))
    ' if control comes here, the array doesn't contain
    ' any duplicate values, so we can return zero
    HasDuplicateValues = False

End Function
Francesco Balena
Comment and Contribute






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



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