Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Other Programming > VBScript
VBScript For questions and discussions related to VBScript.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VBScript section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old April 14th, 2008, 11:03 AM
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
             End If
             If strMatch <> True Then
                f.writeline strLine1
          End If
End Function
Reply With Quote

Similar Threads
Thread Thread Starter Forum Replies Last Post
Compare 2 Text Files mollem VBScript 5 April 16th, 2016 09:35 AM
Source on Java to compare XML files like ExamXML alapick XML 1 July 28th, 2006 04:05 AM
Compare two xml files using xslt sudha XSLT 0 March 10th, 2006 01:04 AM
Is there any tool available to compare 2 xml files parekh_bhakti ASP.NET 1.0 and 1.1 Professional 1 October 28th, 2005 12:59 PM
compare two xml files attributes, elements k_s_ashok XML 1 June 9th, 2004 02:08 AM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.