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 two strings

Status
Not open for further replies.

sfriday

IS-IT--Management
Feb 23, 2002
211
DE
I want to read two files, compare the first line of the first file with the first line of the second and then the second of the second and so on, when I hit the end of the second file I move to the second line of the first and carry on again. If at the end of the first pass the line in the first file does not exist in the second then write it out to a third file.

Confusing hey!!

here is where I got to with the code

Set objReader = FSO.OpenTextFile(OutFile)
Set objReader2 = FSO.OpenTextFile(TempFile)
Set objWriter = FSO.OpenTextFile(FinalFile,ForAppending)
Do While not objReader.AtEndOfStream
strline = objReader.ReadLine
Do While not objReader2.AtEndOfStream strline2 = objReader2.Readline
If StrComp(strline,strline2,vbTextCompare) = -1 Or StrComp(strline,strline2,vbTextCompare) = 1 Then
what do I put in here
End If
Loop
objWriter.WriteLine(strline)

now I now that I have got my write in the wrong place as if the last line of the second file does not compare it will write out to the third file regardles of all the other looped checks.

Is there another way of checking for the existance of something within a file without reading in each line, IE some sort of scan of the file.

Thanks
Steve

HELP!!!

I hope this makes sence

Regards
Steve
 
sfriday,


Instead of using:
strline = objReader.ReadLine
you may want to use:
strline = objReader.Readall

This will read the whole file instead of line by line.


fengshui_1998
 
I would do nested while...wend loops, kinda like you have done.

while not objreader.EOF
match = "no"
strline = objreader.Readline

while not objreader2.EOF
strline2 = objreader2.Readline

if strline = strline2 then
match = "yes"
end if

wend

if match = "no" then
objwriter.WriteLine(strline)
end if
wend

This looks like it should work. By the time the inner while...wend completes, if match is still equal to no, then that means it wasn't found and that you do want to write it out. It does this within the first while...wend, and repeats the process until the first file hits EOF.

This is slightly different from the way you've done it. Adapt as necessary.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top