41 lines
960 B
Plaintext
41 lines
960 B
Plaintext
Function RemoveDuplicatesFromArray(arrItems)
|
|
|
|
'Source: https://devblogs.microsoft.com/scripting/how-can-i-delete-duplicate-items-from-an-array/
|
|
|
|
If (Ubound(arrItems) >= 0) Then
|
|
|
|
If (DEBUG_ON = True) Or (DebugMode = "Enabled") Then
|
|
MSGBOX "Array count: " & (Ubound(arrItems)+1),,"DEBUG - Info: BEFORE deduplication!"
|
|
End If
|
|
|
|
Set objDictionary = CreateObject("Scripting.Dictionary")
|
|
|
|
For Each strItem in arrItems
|
|
If Not objDictionary.Exists(strItem) Then
|
|
objDictionary.Add strItem, strItem
|
|
End If
|
|
Next
|
|
|
|
intItems = objDictionary.Count - 1
|
|
|
|
ReDim arrItems(intItems)
|
|
|
|
i = 0
|
|
|
|
For Each strKey in objDictionary.Keys
|
|
arrItems(i) = strKey
|
|
i = i + 1
|
|
Next
|
|
|
|
'For Each strItem in arrItems
|
|
' msgbox strItem
|
|
'Next
|
|
|
|
If (DEBUG_ON = True) Or (DebugMode = "Enabled") Then
|
|
MSGBOX "Array count: " & (Ubound(arrItems)+1),,"DEBUG - Info: AFTER deduplication!"
|
|
End If
|
|
|
|
End If
|
|
|
|
RemoveDuplicatesFromArray = arrItems
|
|
End Function |