VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



'Return the distinct element from string array

by Dhaval Amin (1 Submission)
Category: String Manipulation
Compatability: Visual Basic 5.0
Difficulty: Unknown Difficulty
Originally Published: Fri 18th May 2007
Date Added: Mon 8th February 2021
Rating: (1 Votes)

'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



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

Download this snippet    Add to My Saved Code

'Return the distinct element from string array Comments

No comments have been posted about 'Return the distinct element from string array. Why not be the first to post a comment about 'Return the distinct element from string array.

Post your comment

Subject:
Message:
0/1000 characters