Avatar of -Geek
-Geek asked on

Visual Basic Compare Documents

Greetings,

 I am looking to compare documents to output the differences between them in Visual Basic. Looking for an add-on with clear directions on use and examples. What I am currently using is ok to compare, but if their is one word different then the detection is worthless.

Private Function FileCompare(ByVal file1 As String, ByVal file2 As String) As Boolean
        Dim file1byte As Integer
        Dim file2byte As Integer
        Dim fs1 As FileStream
        Dim fs2 As FileStream

        If (file1 = file2) Then
            Return True
        End If

        fs1 = New FileStream(file1, FileMode.Open)
        fs2 = New FileStream(file2, FileMode.Open)

        If (fs1.Length <> fs2.Length) Then
            fs1.Close()
            fs2.Close()
            Return False
        End If

        Do
            file1byte = fs1.ReadByte()
            file2byte = fs2.ReadByte()
        Loop While ((file1byte = file2byte) And (file1byte <> -1))

        fs1.Close()
        fs2.Close()

        Return ((file1byte - file2byte) = 0)
    End Function

Open in new window

Visual Basic.NET

Avatar of undefined
Last Comment
-Geek

8/22/2022 - Mon
aikimark

1. Are these text/document type files or binary data?
2. How will the output of this function be used?
ASKER
-Geek

These are word documents, the Microsoft comparison above is a byte by byte I believe.
aikimark

Do your users have Word on their systems?  If so, why not use Word's document comparison functionality?
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
ASKER
-Geek

They don't I had thought about that already.
aikimark

If the users do not have Word on their PCs, then why are they trying to compare their contents?!?

Have you looked at the Open Office SDK?  I know that it allows your VB.Net program to work with documents, especially the .docx format.  That will be helpful in parsing the contents of the documents.

I would recommend looking at some libraries or utilities that do document comparison and see if you might be able to launch them from your application and then present the results.

Is it possible to use these two documents as parameters to a web service call?  Maybe you can install Word on your server.
ASKER
-Geek

Didn't think if that, do you have any links?
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER CERTIFIED SOLUTION
aikimark

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
-Geek

I have about 7 - 10 documents to compare to 1, and most I found for that are in c#. Do you know of any examples in VB that I could utilize? Looks promising.
aikimark

do it manually.  For that few documents, you shouldn't expend any of your time coding.
ASKER
-Geek

7 - 10 at a time, it spans in the upwards of sometimes 30 documents, and this is by 5 individuals so it's quite a large task ( 5 x 30 ). Sorry for not being clear enough. I am looking to add more folks to the document pool so currently at 5 but don't want to add more until I can nail this task.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ASKER
-Geek

Thank you very much, will open further questions around findings.