Hey all, I have a problem in comparing two text files in visual basic 6
First need to compare the first line of text files, and if its different, find the missing line(s)
Content of text file 1:
2
asd.txt
ase.txtContent of text File 2:
1
asd.txt
someone guide me plzz
did u have tried searching in net.
http://www.google.com/search?q=compare+files+in+vb6&sourceid=ie7&rls=com.microsoft:en-us:IE-SearchBox&ie=&oe=
Yes i did google..
But i couldnt understand
I hv zero programming knowledge in VB
this is assuming that both files are sorted (after the first line, which i am also assuming is the linecount of each file): dim x$(2)
open "file1" for input as #1
open "file2" for input as #2
gosub read
if x$(2)>x$(1) then ex=val(x$(2)) else ex=val(x$(1))
do while not eof(ex)
for i=1 to 2
gosub read
next i
for i=1 to 2
if x$(3-i)>x$(i) then
print "file ";3-i;" is missing line ";x$(i)
goto xit
next i
loop
print "files same"
goto xitread:
if eof(i) then print "eof";i : goto xit
line input #i,x$(i)
return
xit:
end
probably better suggestion: strip off the first line then do "fc" on the two files.
edlin: 1d,e will remove line 1 when set up corr.
Thanks alot nbrane,
However i also did some search and solved this problem
Just want share here for other to refer and learn;FileA = "C:\LOGFILES\abc.log"
FileB = "C:\LOGFILES\cba.log"
Set fso = New FileSystemObject
Set FileA1 = fso.OpenTextFile(FileA, ForReading)
Count = 1
Do Until FileA1.AtEndOfStream
strMatch = False
strFileA = FileA1.ReadLine
Set FileB1 = fso.OpenTextFile(FileB, ForReading)
Do Until FileB1.AtEndOfStream
strFileB = FileB1.ReadLine
If Trim(UCase(strFileB)) = Trim(UCase(strFileA)) Then
strMatch = True
End If
Loop
FilebB1.Close
'Avoid Difference in First Line
If Not (Count = 1) Then
If strMatch <> True Then
print strFileA
End If
Else
If strMatch <> True Then
print "File Missing"
End If
End If
Count = Count + 1
Loop
FileA1.CloseWorking fine to me, correct me if wrong!!!
Yes (14) | ![]() | |
No (14) | ![]() | |
I don't know (15) | ![]() |