Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sorting single instances in a list 1

Status
Not open for further replies.

IainBuchanan

Technical User
Aug 1, 2000
16
GB
Hi,

I'm not the greatest of VBScripters, and am banging my head against the desk with a problem. I've got a list and I need to display those items that appear only once in the list.

I've actually got two lists, but then I'm combining them into one list.

I can sort and display unique items in the list, but this then gives me a list of all items, but only one instance per item. What I need is to display only those items that have a single instance.

eg In a list of:

one
two
three
four
two
three

I would need to get the result of:

one
four

Any help on this one would be much appreciated!!!

Cheers.

Iain Buchanan
 
one possible method...add them to dictionary object

Set dicTest = CreateObject("Scripting.Dictionary")
For Each aThing In aList
If Not dicTest.Exists(LCase(aThing)) Then
dicTest.Add LCase(aThing), 1
Else
dicTest.Item(LCase(aThing)) = dicTest.Item(LCase(aThing)) + 1
End If
Next

For Each aThing In dicTest
If dicTest.Item(aThing) = 1 Then
Wscript.Echo aThing & " single instance"
End If
Next
 
no problem, had a thought that it wouldnt actually sort them for you afterwards...you would have to bubble sort as well, plus you would have to find away for vbscript to recognise that

"one" < "two" < "three" etc etc
 
I wasn't too worried about them being sorted as such, as the original two lists are actually directory listings, which I'd sorted at the time of creating the listings in VBS.

Iain Buchanan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top