Code in VB6 showing text file differences:

Does anyone have some code I can put into my Application comparing 2 text files and showing the difference between the two files. If you have code for an entire app to do this that would be great, but if not thats OK too. I'm using VB6.
revisAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Michael_DCommented:
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
anvCommented:
try this

Public Function AreTheyTheSame(ByVal File1 As String, _
  ByVal File2 As String, Optional StringentCheck As _
  Boolean = False) As Boolean
'**********************************************************
'PURPOSE: Check to see if two files are identical
'File1 and File2 = FullPaths of files to compare
'StringentCheck (optional): If false (default),
'will only compare file lengths.  If true, a
'byte by byte comparison is conducted if file lengths are
'equal
'**********************************************************

On Error GoTo ErrorHandler

If Dir(File1) = "" Then Exit Function
If Dir(File2) = "" Then Exit Function

Dim lLen1 As Long, lLen2 As Long
Dim iFileNum1 As Integer
Dim iFileNum2 As Integer
Dim bytArr1() As Byte, bytArr2() As Byte
Dim lCtr As Long, lStart As Long
Dim bAns As Boolean

lLen1 = FileLen(File1)
lLen2 = FileLen(File2)
If lLen1 <> lLen2 Then
    Exit Function
ElseIf StringentCheck = False Then
        AreTheyTheSame = True
        Exit Function
Else
    iFileNum1 = FreeFile
    Open File1 For Binary Access Read As #iFileNum1
    iFileNum2 = FreeFile
    Open File2 For Binary Access Read As #iFileNum2

    'put contents of both into byte Array
    bytArr1() = InputB(LOF(iFileNum1), #iFileNum1)
    bytArr2() = InputB(LOF(iFileNum2), #iFileNum2)
    lLen1 = UBound(bytArr1)
    lStart = LBound(bytArr1)
   
    bAns = True
    For lCtr = lStart To lLen1
        If bytArr1(lCtr) <> bytArr2(lCtr) Then
            bAns = False
            Exit For
        End If
           
    Next
    AreTheyTheSame = bAns
       
End If
 
ErrorHandler:
If iFileNum1 > 0 Then Close #iFileNum1
If iFileNum2 > 0 Then Close #iFileNum2
End Function
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.