CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2001
    Posts
    11

    Problem with compare two large text file

    I am wondering is there a way or different method to compare two large text file without taking up so much time. I tried the FC.exe command and it did it very fast, but when I try to compare it in my VB program, it takes forever to finish with following code.

    open FN1 for input as #1
    while not eof(1)
    line input #1, Str1
    open FN2 for input as #2
    do while not eof(2)
    line input #2, Str2
    if (Str1 = Str2) then
    bfound = true
    exit do
    end if
    loop
    wend

    Thanks you in advance


  2. #2
    Join Date
    Aug 2000
    Location
    Ottawa, Canada
    Posts
    469

    Re: Problem with compare two large text file

    First of all I would remove opening statement from the loop.


  3. #3
    Join Date
    May 2000
    Location
    New York, NY, USA
    Posts
    2,878

    Re: Problem with compare two large text file

    Try to compare in binary mode. It must speed it up

    'Description: Compares the content of two files

    Open "file1" For Binary As #1
    Open "file2" For Binary As #2
    issame% = True
    If LOF(1) <> LOF(2) Then
    issame% = False
    Else
    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
    issame% = False
    Exit For
    End If
    start& = start& + 10000
    Next
    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 issame% = False
    End If
    Close
    If issame% Then
    MsgBox "Files are identical", 64, "Info"
    Else
    MsgBox "Files are NOT identical", 16, "Info"
    End If

    Iouri Boutchkine
    [email protected]
    Iouri Boutchkine
    [email protected]

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

Featured