i had an array with duplicate values

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • chandru8
    New Member
    • Sep 2007
    • 145

    i had an array with duplicate values

    hi to all
    i had an array with duplicate values like
    a(1) = "A"
    a(2) ="B"
    a(3) = "C"
    a(4) = "A"
    a(5) = "A"
    A value has been repeated so that i need to concateate "Dup" to that value
    a(1) = "ADuplicate "
    a(2) ="B"
    a(3) = "C"
    a(4) = "A"
    a(5) = "A"

    other than this "A" should not be altered.
    thanks for your help in advance
    its urgent,
  • QVeen72
    Recognized Expert Top Contributor
    • Oct 2006
    • 1445

    #2
    Hi,

    4th and 5th Values also have "A".. you dont want to concatenate "Dup" to those Items..?


    REgards
    Veena

    Comment

    • chandru8
      New Member
      • Sep 2007
      • 145

      #3
      hi thanks for you reply
      we need to conc for only one value

      Comment

      • QVeen72
        Recognized Expert Top Contributor
        • Oct 2006
        • 1445

        #4
        Hi,

        Try this code:

        tarr >> is your Array
        narr is Array with new values..

        [code=vb]
        Private Sub Command_Click()
        '
        Dim j As Integer
        Dim i As Integer
        Dim TStr As String
        Dim TFlag As Boolean
        Dim TItem As Integer
        Dim tarr(1 T 10)
        Dim narr(1 To 10)
        '
        ' Write code here To Redim new array
        '
        For i = LBound(tarr) To UBound(tarr)
        TItem = -1
        TFlag = False
        TStr = tarr(i)
        For j = 1 To (i - 1)
        If TStr = tarr(j) Then
        TFlag = True
        TItem = j
        Exit For
        End If
        Next
        narr(i) = TStr
        If TFlag Then
        narr(TItem) = TStr & "Dup"
        End If
        Next
        End Sub
        [/code]

        at the end write one more for loop to transfer data from narr to tarr..


        REgards
        Veena

        Comment

        Working...