View Single Post
  #1 (permalink)  
Old April 14th, 2008, 11:03 AM
mtnguye6 mtnguye6 is offline
Registered User
 
Join Date: Apr 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default compare 2 files and output third files

I have 2 files, 1 files from excel named result.xls and other files is compare.txt.
I want to compare both files and find the same name and wite the value to the same name in next sheet.
from VBscript, how can I do that. I have created script here but don't know is tthis is work. can expert other help me thanks

Function compare_result()
    Const ForReading = 1, ForWriting = 2
        Dim fso, txtFile, txtFile2, strLine1, strLine2, strMatch

            Set fso = CreateObject("Scripting.FileSystemObject")
            Set txtFile1 = fso.OpenTextFile("Result.xls", ForReading)
            Set f = fso.OpenTextFile("New_result.xls", ForWriting, True)

        Do Until txtFile1.AtEndOfStream
            strMatch = False
                strLine1 = txtFile1.Readline
            Set txtFile2 = fso.OpenTextFile("compare.txt", ForReading)
        Do Until txtFile2.AtEndOfStream
            strLine2 = txtFile2.Readline
                If Trim(UCase(strLine2)) = Trim(UCase(strLine1)) Then
                    strMatch = True
                Else
             End If
        Loop
        txtFile2.Close
             If strMatch <> True Then
                f.writeline strLine1
          End If
        Loop
End Function
Reply With Quote