Results 1 to 5 of 5

Thread: [RESOLVED] How to check duplicate digit?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2007
    Posts
    227

    Resolved [RESOLVED] How to check duplicate digit?

    Dear all expert programmer,
    I want to make project to check duplicate digit. Please see data below.

    set1 = "0123-4506"
    set2 = "1234-4506-8899"
    set3 = "0123-1234-4506"

    Summary data is "0123-4506-1234-4506-8899-0123-1234-4506"

    After check duplicate in all set it will be show result below

    Dup3 = "4506" (That mean it have number of 4506 = 3)
    Dup2 = "0123-1234" (That mean have number of 0124 and 1234 = 2)
    Dup1 = "8899" (That mean it have number of 8899 = 1)

    Please tell me how to code it.

    Thank you for all answer.
    Last edited by standardusr; Dec 20th, 2007 at 07:43 AM.

  2. #2
    PowerPoster
    Join Date
    Nov 2002
    Location
    Manila
    Posts
    7,629

    Re: How to check duplicate digit?

    You will have to explain more clearly the logic behind output values Dup1, Dup2, Dup3... does Dup1 mean one instance in all sets, Dup2 mean two instances in all sets etc?

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Aug 2007
    Posts
    227

    Re: How to check duplicate digit?

    OK, Please see above again.

  4. #4

  5. #5
    Hyperactive Member
    Join Date
    Aug 2006
    Location
    TeXaS
    Posts
    497

    Re: How to check duplicate digit?

    maybe this is an idea of what your wanting..
    i just tossed it together to let you sample it. you could easily convert it to a function to fit your needs. im thinking there is an easier way, but for now this is what came to mind.

    Code:
    Option Explicit
    
    Private Type fData
        fStr As String
        fCount As Long
    End Type
    
    
    Private Sub Command1_Click()
    
        Dim iSet(1 To 3) As String
        Dim sArray() As String
        Dim UbArray As Long
        Dim dHold As String
        Dim iCount As Long, fCount As Long
        Dim i As Long
        Dim iFind() As fData
        ReDim iFind(0)
        
        iSet(1) = "0123-4506"
        iSet(2) = "1234-4506-8899"
        iSet(3) = "0123-1234-4506"
        
        sArray = Split(Join(iSet, "-"), "-")
        
        UbArray = UBound(sArray)
        
        fCount = 0
        
        Do
            dHold = sArray(iCount)
            iFind(fCount).fStr = dHold
            iFind(fCount).fCount = 1
            For i = iCount + 1 To UbArray
                If sArray(i) = dHold Then 'found one
                    sArray(i) = vbNullString
                    iFind(fCount).fCount = iFind(fCount).fCount + 1
                End If
            Next i
            Do ' pass through the empty elements of sArray (if any)
                iCount = iCount + 1
                If iCount > UbArray Then
                    Exit Do
                End If
            Loop Until sArray(iCount) <> vbNullString
            If iCount > UbArray Then
                Exit Do
            End If
           
            If iFind(fCount).fCount > 0 Then
                fCount = fCount + 1
                ReDim Preserve iFind(0 To fCount)
            End If
        Loop
        
        For i = 0 To UBound(iFind)
            MsgBox iFind(i).fStr & " = " & iFind(i).fCount
        Next i
    
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width