'Return the distinct element from string array
'Return the distinct element from string array
API Declarations
Dim s1(9) As String
Dim s2(0) As String
Dim arrayblank As Boolean
Dim Found As Boolean
s1(0) = "Dhaval"
s1(1) = "Test"
s1(2) = "Array Index 2"
s1(3) = "Test"
s1(4) = "Dhaval"
s1(5) = "Dhaval"
s1(6) = "Array Index 6"
s1(7) = "VB6"
s1(8) = "VB6"
s1(9) = "Dhaval"
Rate 'Return the distinct element from string array
(1(1 Vote))
arrayblank = True
'start check form element 0
For x = 0 To 9
'when start check from next element counter = 0
elementCounter = 0
For y = x To 9
If s1(x) = s1(y) Then
'if found same value, counter increase
elementCounter = elementCounter + 1
End If
Next y
If arrayblank = True Then
arrayblank = False
s2(0) = s1(x)
Else
For z = LBound(s2) To UBound(s2)
'tmp = Split(s2(w), ",")
If s2(z) = s1(x) Then
Found = True
Exit For
Else
Found = False
End If
Next z
If Found = False Then
ReDim Preserve s2(UBound(s2) + 1)
s2(UBound(s2)) = s1(x) '& "," & z
End If
End If
Next x
'Display unique array with counter
For x = LBound(s2) To UBound(s2)
Debug.Print s2(x)
Next x
'Return the distinct element from string array Comments
No comments yet — be the first to post one!
Post a Comment