Jump to content

dreamscapeuk

Members
  • Content Count

    1
  • Joined

  • Last visited

Community Reputation

0 Neutral

About dreamscapeuk

  • Rank
    Newbie
  1. Hi there, I'm new to vbscripting so please help..I have 2 txt files with data like belowFile 1A/C Value40000 -1908363.0040100 20000.0040200 350004.0040300 -3498.99File 2A/C Value40000 -1908363.0040105 -234567.0040200 350.0040300 -3498.99Both files are in the same format (finally!) and I'm trying to compare them to list only the lines that are different in each file. First I did the standard read each line in file 1 and compare to all the lines of file 2 but this will miss anything in file 2 that isn't in file 1 unless i do the same in reverse. Someone suggested I put both files in a dictionary and compare. I have made an attempt but keep getting this error: Line 33: This key is already associated with an element of this collection.Also I'm not sure the results will be what i'm expecting as I wanted to get something like this:A/C File 1 File 240100 20000.00 ' where the account only exists in file 140105 -234567.00 ' where the account only exists in file 240200 350004.00 350.00 ' where the accoun exists in both files but the values are different.Any help please??????Here's my code: Const ForReading = 1, ForWriting = 2Set objDictionary = CreateObject("Scripting.Dictionary")' Declare the dictionaries.Dim Dict1 Dim Dict2 'Set txt filesSet objFSO = CreateObject("Scripting.FileSystemObject")Set objTextFile = objFSO.OpenTextFile("C:\VBScript\ReadFiles\OracleFile.txt", ForReading)Set objTextFile2 = objFSO.OpenTextFile("C:\VBScript\ReadFiles\HyperionFile.txt", ForReading)Set f = objFSO.OpenTextFile("C:\VBScript\ReadFiles\ResultsFile.txt", ForWriting, True)Set Dict1 = objDictionaryWith Dict1  'set compare mode.CompareMode = BinaryComparei = 0Do Until objTextFile.AtEndOfStream     strNextLine = objTextFile.Readline   .Add i, strNextLine    i = i + 1LoopEnd WithSet Dict2 = objDictionaryWith Dict2  'set compare mode.CompareMode = BinaryCompare  i = 0Do Until objTextFile2.AtEndOfStream     strNextLine2 = objTextFile2.Readline   .Add i, strNextLine2    i = i + 1LoopEnd With' Compare the two dictionaries.For Each objItem In Dict1  If    Dict2.Exists(objItem) Then            Dict2.Remove(objItem)            Dict1.Remove(objItem)  Else         f.writeline Dict1(objItem) & vbCrLf        f.writeline Dict2(objItem) & vbCrLf  End if    Nextf.CloseWScript.Echo "Done"
×
×
  • Create New...