Eliminate Duplicates and Extract Partial Matches From List

Again requiring some help and direction. I was given a list of songs titles with their performers and asked if I could come up with something which could remove any duplicates from the list and hive off another list which would show all cases where the same song was sung by a number of different performers. Mistakenly, I thought this would be relatively straightforward but I have ended up more than a little confused.

I thought I would eliminate the duplicates by reading the data into an array, exporting it to the "dictionary" and then writing it back. That seems to have worked OK. I then read the data (title and performer) into an array and ran a Title match. This should have resulted in a "match" against each entry in the New_Array.txt file, and it did, except that it kept omitting one of the titles from the output file ie the differences.txt output file should have had 12 entries but only ever produced 11 and nothing I did made any difference (it omitted Rivers of Babylon if processed in the same order as I did). What I was trying to do was to modify this "match" in some way so that the code identified only those cases where the same song was sung by different performers and wrote these to the differences file.

I would appreciate any direction

Thank you

The list is way too long to incude so here is a "sample" of the type of entries and the code

I have so far:

Audio_List.txt
Rivers Of Babylon~Boney M*
Bohemian Rhapsody~Queen*
Mull Of Kintyre~Wings*
Loving Her Was Easier Than Anything I'll Ever Do Again~Jose Feliciano*
Country Roads~Olivia Newton John*
Loving Her Was Easier Than Anything I'll Ever Do Again~Lloyd Charmers*
Bohemian Rhapsody~Queen*
She Loves You~Beatles*
Loving Her Was Easier Than Anything I'll Ever Do Again~Tompall And The Glaser Brothers*
Do They Know It's Christmas~Band Aid*
She Loves You~Beatles*
Elizabethan Serenade~Boris Gardiner*
I Want To Wake Up With You~Boris Gardiner*
She Loves You~Beatles*
Country Roads~Toots And The Maytalls*
Loving Her Was Easier Than Anything I'll Ever Do Again~Lloyd Charmers*

As you will see there are some duplicates which the Dictionary object resolved but the
Difference file should only have shown:

Differences.txt
Loving Her Was Easier Than Anything I'll Ever Do Again~Jose Feliciano
Loving Her Was Easier Than Anything I'll Ever Do Again~Lloyd Charmers
Loving Her Was Easier Than Anything I'll Ever Do Again~Tompall And The Glaser Brothers
Country Roads~Olivia Newton John
Country Roads~Toots And The Maytalls


[Code
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8

Set objFSO = CreateObject("Scripting.FileSystemObject")

'Read in file
Set objFile1 = objFSO.OpenTextFile("C:\Test\Audio_List.txt", ForReading)
strCurrentFile = objFile1.ReadAll

'Read string into array
arrItems = Split(strCurrentFile,"*",-1,0)

objFile1.Close



'Create Dictionary
Set objDictionary = CreateObject("Scripting.Dictionary")


'Add array to dictionary
For Each strItem in arrItems

If Not objDictionary.Exists(strItem) Then
objDictionary.Add strItem, strItem
End If
Next

'Determine number of entries
intItems = objDictionary.Count - 1

'Redimension array
ReDim arrItems(intItems)


'Read dictionary contents back into redim array
i = 0

For Each strKey in objDictionary.Keys
arrItems(i) = strKey
i = i + 1
Next

'Originally used as a check Point to see if duplicates were eliminated
Set objFile2 = objFSO.OpenTextFile("C:\Test\New_Array.txt", ForWriting,True,0)
For Each strItem in arrItems
strItem = Replace(strItem,vbCRLF,"",1,-1,0)

objFile2.writeLine strItem

Next

'Read Data into variable
Set objFile3 = objFSO.OpenTextFile("C:\Test\New_Array.txt",ForReading)

strCurrent = objFile3.ReadAll

objFile3.Close

'Read data into variable for title extraction
Set objFile4 = objFSO.OpenTextFile("C:\Test\New_Array.txt", ForReading)

Do Until objFile4.AtEndOfStream

strAddress = objFile4.ReadLine
strPoint = Instr(1,strAddress,"~",0)


strTitle = left(strAddress,strPoint

'Match title against variable
If InStr(strCurrent, strTitle) > 1 Then

strNowCurrent = strNowCurrent & strAddress & vbCRLF

End If

Loop

'Write out differences to file
Set objFile5 = objFSO.OpenTextFile("C:\Test\Differences.txt",ForWriting,True,0)

objFile5.Write strNowCurrent
objFile5.Close

[/Code]
 

My Computer

My Computer

System One

  • Manufacturer/Model
    Dell XPS420
    Memory
    6 gig
    Graphics Card(s)
    ATI Radeon HD3650 256 MB
    Sound Card
    Intergrated 7.1 Channel Audio
    Monitor(s) Displays
    Dell SP2009W 20 inch Flat Panel w Webcam
    Hard Drives
    640 gb
    Cooling
    Fan
    Keyboard
    Dell USB
    Mouse
    Dell USB 4 button optical
    Other Info
    DSL provided by ATT
Hi Rich, I was aware that this could be done under Vista but unfortunately I am required to use VBS as this has to link in with other VBS items. However, other newbies may not be aware so the information will be useful to them.

Thank you anyway for your response
 

My Computer

Back
Top