non_repeate_values_in array

L

layla

Hi,
I have an array consists of some repeated values(i.e 1,2,2,3,3,5,6,7)
I need to write a code to say which numbers are repeated(ie 2,3) ,and
how many are they
and
which numbers are not repeated (1,5,6,7),and how many are they
I attemptteh following code but it does not work
'If NumNodes > 1 Then

' For i = 1 To NumNeedlines
' temp = strNam(i)
' For j = i + 1 To NumNeedlines
' If (temp = strNam(j)) Then
icounter = icounter + 1
'common(icounter) = temp
else
jcounter=jcounter+1
different(jcounter)=temp
'End If
'Next j
'Next i
 
A

AlEdlund

Layla,
You're beginning to sound remarkably like a student coming here for their
programming homework assignments. You might consider applying a 'collection'
or 'dictionary' to this type of a problem since your working with tuples
(key, value).
al
 
D

David J Parker [MVP Visio]

Add a reference to Microsoft Scripting Runtime

Public Sub ListRepeats()
Dim ary() As String
ary = Split("1,2,2,3,3,5,6,7", ",")

Dim dic As Dictionary
Set dic = New Dictionary
Dim icounter As Integer
Dim jcounter As Integer
Dim key As String

For icounter = 0 To UBound(ary)
key = ary(icounter)
If dic.Exists(key) Then
dic(key) = dic(key) + 1
Else
dic.Add key, 1
End If
Next

Dim dups() As String
For icounter = 1 To dic.Count
key = dic.Keys(icounter - 1)
If dic(key) = 1 Then
ReDim Preserve dups(jcounter)
dups(jcounter) = key
jcounter = jcounter + 1
End If
Next

MsgBox Join(dups, ","), vbExclamation

End Sub
 
D

David J Parker [MVP Visio]

Oh dash ... I've just done her homework!

AlEdlund said:
Layla,
You're beginning to sound remarkably like a student coming here for their
programming homework assignments. You might consider applying a
'collection' or 'dictionary' to this type of a problem since your working
with tuples (key, value).
al
 
A

AlEdlund

:) Just one of those days. I was just looking for the Visio content and
was seeing (in my amateur role) what appeared to be some pretty basic (no
pun intended) questions.
How goes the battle with the evil developer that's trying to take away your
'greenland'? You mentioned in your BLOG the decision would be coming in
September.
Al
 
D

David J Parker [MVP Visio]

It's now on or before the 4th November!

AlEdlund said:
:) Just one of those days. I was just looking for the Visio content and
was seeing (in my amateur role) what appeared to be some pretty basic (no
pun intended) questions.
How goes the battle with the evil developer that's trying to take away
your 'greenland'? You mentioned in your BLOG the decision would be coming
in September.
Al
 
A

AlEdlund

suspect it should read (assumes microsoft.scripting.runtime has been
referenced in the tools=>references)

dim dic as scripting.dictionary
set dic = new sripting.dictionary

al
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top