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("C:\Windows\Desktop\test3.txt", ForWriting, True)
' h.WriteLine Inline3
' 'h.close
loop
End Function
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("C:\Windows\Desktop\test3.txt", ForWriting, True)
' h.WriteLine Inline3
' 'h.close
loop
End Function