Results 1 to 3 of 3

Thread: [VB6] Text Differences

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2007

    [VB6] Text Differences

    Say I have 2 files, and they are both different. One has more stuff than others.

    File1: "Hello"
    File2: "Hello1 Hello"

    How could I compare the 2 files, find the differences in text, and add the differences to the first file?

  2. #2
    Frenzied Member
    Join Date
    Oct 2003

    Re: [VB6] Text Differences

    Testing if two strings are not the same is easy.

    Finding what the differences are is trickier.
    In your example, would File2 be File1 & "1 Hello" or would it be "Hello1 "& File1?

    What do you want to do?
    What are these files?
    What kind of data do they contain and how ae they formatted?

  3. #3
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Searching for mendhak

    Re: [VB6] Text Differences

    Try this
    Private Function CompareFiles(FirstFile As String, SecondFile As String) As Boolean
    'Description: Compares the content of two files
    Dim Part As Long
    Dim Whole As Long
    Dim Part As Long
    Dim Start As Long
    Dim Buffer1 As String
    Dim Buffer2 As String
    Dim x As Long
    Open FirstFile For Binary As #1
    Open SecondFile For Binary As #2
    CompareFiles = True
    If LOF(1) <> LOF(2) Then
        CompareFiles = False
        Whole = LOF(1) \ 10000         'number of whole 10,000 byte chunks
            Part = LOF(1) Mod 10000        'remaining bytes at end of file
            Buffer1 = String$(10000, 0)
            Buffer2 = String$(10000, 0)
            Start = 1
            For x = 1 To Whole            'this for-next loop will get 10,000
            Get #1, Start, Buffer1      'byte chunks at a time.
            Get #2, Start, Buffer2
            If Buffer1 <> Buffer2 Then
                CompareFiles = False
                    Exit For
            End If
            Start = Start + 10000
            Buffer1 = String$(Part, 0)
            Buffer2 = String$(Part, 0)
            Get #1, Start, Buffer1        'get the remaining bytes at the end
            Get #2, Start, Buffer2        'get the remaining bytes at the end
            If Buffer1 <> Buffer2 Then CompareFiles = False
            End If
            Close #1
            Close #2
            If CompareFiles Then
                MsgBox "Files are identical"
                MsgBox "Files are NOT identical"
            End If
    End Function
    I don't remember where I got it, but I've used it a couple of times and it seems to work fine.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Click Here to Expand Forum to Full Width