|
-
Dec 20th, 2007, 07:05 AM
#1
Thread Starter
Addicted Member
[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.
-
Dec 20th, 2007, 07:38 AM
#2
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?
-
Dec 20th, 2007, 07:44 AM
#3
Thread Starter
Addicted Member
Re: How to check duplicate digit?
OK, Please see above again.
-
Dec 20th, 2007, 11:11 AM
#4
Re: How to check duplicate digit?
I'm sorry but your improved explanation still doesn't help (at least me). In any case isn't this the same question as in this other thread?
-
Dec 20th, 2007, 06:37 PM
#5
Hyperactive Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|