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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Browse for text files and Compare 2

Status
Not open for further replies.

Nu2Java

Technical User
Jun 5, 2012
166
US
Hi,

I found this code from "The Scripting Guy" for comparing 2 files and output changes. This works great for what I need.... What I would like to have is a "Browse For File" function for the text files. Is there any easy way to do this? Thanks for any help... I am going to keep searching in the meantime.

Code:
Const ForReading = 1

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile1 = objFSO.OpenTextFile("C:\Temp\NewRev.txt", ForReading)

strCurrentDevices = objFile1.ReadAll
objFile1.Close

Set objFile2 = objFSO.OpenTextFile("C:\Temp\OldRev.txt", ForReading)

Do Until objFile2.AtEndOfStream
    strAddress = objFile2.ReadLine
    If InStr(strCurrentDevices, strAddress) = 0 Then
        strNotCurrent = strNotCurrent & strAddress & vbCrLf
    End If
Loop

objFile2.Close

Wscript.Echo "Changes since last revision: " & vbCrLf & strNotCurrent

Set objFile3 = objFSO.CreateTextFile("C:\Temp\Changes.txt")

objFile3.WriteLine strNotCurrent
objFile3.Close
 
Geates,
Here is my output file:

Code:
******************************************************************************************
Compared this file: C:\temp\80-777-01 r1.txt
Against this file: C:\temp\80-777-01 r2.txt
******************************************************************************************

Changes to Last Revision: 

(Target Machine: CAD-109)

New Revision File: 

0/2012 10:28:12)
N0002 (Part Number: 47-054020-10)
N0003 (Target Machine: CAD-107)
N0004 (Solder Alloy: Leaded)
N0005 (Nozzle 1: 9mm)
N0006 (Nozzle 2: 6mm)
N0007 (Soldering with Nozzle 1 first)
N0008 (Zero Point: LOWER LEFT FID)
N0009 G20 (Inch Units)
N0010 G52 X0.000 Y0.000 (OFFSET)
O1000 (BEGIN PROGRAM)

I changed just one character in N0003 line and it picked up the change just fine. But it cut off almost the first 2 lines of this original file:

Code:
N0000 (File Posted with ACC Teach v2.0.40.0)
N0001 (File Posted on 10/10/2012 10:28:12)
N0002 (Part Number: 47-054020-10)
N0003 (Target Machine: CAD-107)
N0004 (Solder Alloy: Leaded)
N0005 (Nozzle 1: 9mm)
N0006 (Nozzle 2: 6mm)
N0007 (Soldering with Nozzle 1 first)
N0008 (Zero Point: LOWER LEFT FID)
N0009 G20 (Inch Units)
N0010 G52 X0.000 Y0.000 (OFFSET)
O1000 (BEGIN PROGRAM)

My code from above with the addition of your code:
Code:
Do Until objSourceFile2.AtEndOfStream
    strAddress = objSourceFile2.ReadLine
    
   strCurrentDevices = right(strCurrentDevices, len(strCurrentDevices) - 6)
   strAddress = right(strAddress, len(strAddress) - 6)
   intLineNum = left(strCurrentDevices, 6)
   intLineNum2 = left(strAddress, 6)
    If InStr(strCurrentDevices, strAddress) = 0 Then
        strNotCurrent = strNotCurrent & strAddress & vbCrLf
    End If
Loop
 
Can anyone help with this? Much appreciated!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top