Comparing two text files is relatively simple. You need to create:
two file handles for opening the files
two string variables to hold the data read from the files
You then read each file line by line into the strings and compare the strings to see if they're the same.
You could also create an output file for recording any differences if you feel it's necessary.
Example:
Filea.txt and Fileb.txt to be compared:
Public Function FileComp(strFileName1 as string, strFileName2 as string) as string
'create the file handles
dim fnum1 as long, fnum2 as long
'create the strings
dim str1 as string, str2 as string
'create return string and a line counter
dim strReturn as string
dim lngLine as long
'allocate the handles and open the files
fnum1 = freefile
open strFileName1 for input as fnum1
fnum2 = freefile
open strFileName2 for input as fnum2
'initialise line no to 0
lngLine = 0
'loop to end of file
while not eof(fnum1)
'add 1 to file num for each linelngLine = lngLine + 1
'read the data
line input #fnum1, str1
line input #fnum2, str2
'compare the variables
if str1 <> str2 then
'no match report error
strReturn = strReturn & _
"Difference at Line " & lngLine & vbCrlf & _
strFileName1 & ": " & str1 & vbCRlf &
sttFileName2 & ": " & str2 & vbcrlf & vbcrlf
end if
wend 'end of loop
'check for different File Sizes
if not eof(fnum2) then
'still data left in file 2
strReturn = strReturn & "Files are different sizes."
end if
'check if any differences
if len(strReturn) > 0 then
'differences detected
FileComp = strReturn
else
'no diff
FileComp = "Files Match"
end if
end function