Results 1 to 4 of 4

Thread: compare contents of 2 files?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,091
    Hi,

    In order to help me with versioning control from a text file that I receive off the web, I was wondering if there was a way to compare the contents of say a text file named categories.txt and categoriesnew.txt.

    I thought about just comparing the size of the 2 files and if there was a difference, I would assume that there has been some updates.. But then I realized that the file size may be identical if the same amount of text was put in as was taken out..

    Anyway to compare the contents of these 2 files to return False if the same or True if different? I'm using VB6 Pro..

    Any help would be appreciated..

    Dan

  2. #2

    Thread Starter
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,091
    Nevermind.. I just found the solution..

    use the LIKE function:

    sResult = "string1" LIKE "string2"

    Returns 0 if False and -1 if True..

    Dan

  3. #3
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    [code]
    'something to think about

    Option Explicit
    Option Compare Text

    Private Sub Form_Load()
    Dim x As String, y As String
    Dim sResult As Boolean
    x = "DirtBagDog"
    y = "DirtBagDog"

    sResult = "x" Like "y"
    If sResult = True Then
    MsgBox "Like = Same"
    Else
    MsgBox "Like = Different"
    End If


    Dim sresult2 As Integer
    sresult2 = StrComp(x, y)
    If sresult2 = 0 Then
    MsgBox "strComp = Same"
    Else
    MsgBox "strComp = Different"
    End If

    End Sub
    [code]
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  4. #4
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    Here's some code I use in one of my oh-so-cool programs
    You could also use Open File For Binary... it's faster.

    Code:
    'first check the filesize
    If FileLen(OLDFILE) <> FileLen(NEWFILE) Then 
    '= updated
    'do all the things you need and
    Exit Sub/Function 'to prevent it to display it's updated twice :)
    End If
    
    'Now the filechecking if the size is the same.
    Open OLDFILE For Input As #1
    Open NEWFILE For Input As #2
    Do While Not EOF(1)
    Line Input #1, tmp1
    Line Input #2, tmp2
    If tmp1 <> tmp2 Then '= Updated!
    'Do the things you need
    Exit Sub/Function
    End IF
    Loop
    
    'If the code reaches here there's nothing updated!

    Get the idea?

    whoohee this is my 800th post
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

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