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

Compare Strings of Text and return Matched Results

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I'm writing VB Script that will Open three files and compares lines text in 2 of them. One matches the text in the other file and then returns the matched results, and then writes it to another file. It seems to return only the first matched result and it will not write it to a file(gives a Permission error). Here's the code I have for it.


Function TextCompare
Set so = CreateObject("Scripting.FileSystemObject")
Set g = so.GetFile("C:\Windows\Desktop\test1.txt")
set ptr2 = g.OpenAsTextStream(ForReading)
set e = so.GetFile("C:\Windows\Desktop\prname.txt")
set ptr1 = e.OpenAsTextStream(ForReading)
cnt = 0
Do While (ptr1.AtEndOfStream <> True)
Inline1 = ptr2.ReadLine(cnt)
Inline2 = ptr1.ReadLine
'WScript.Echo Inline1
cnt = cnt + 1
Do Until (cnt = ptr2.AtEndOfStream)
If Inline1 = Inline2 Then
Inline3 = Inline1
WScript.Echo Inline3
End if
If Inline1 <> Inline2 Then
cnt = cnt + 1
'Inline1 = ptr2.ReadLine(cnt)
'Do While (cnt And ptr2.AtEndOfStream <> True)
'Inline1 = ptr2.ReadLine(cnt)
'Inline2 = ptr1.ReadLine
'Inline4 = Inline1
'WScript.Echo Inline4
'loop
End if
loop

' Set h = pr.OpenTextFile(&quot;C:\Windows\Desktop\test3.txt&quot;, ForWriting, True)
' h.WriteLine Inline3
' 'h.close
loop

End Function
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top