Forum Discussion

lleppert's avatar
lleppert
Contributor
9 years ago

WordDocs.compare throw error on failure

Hello,   I am using the WordDocs script extension to compare two word documents and it is working great. However, when the files do not match it throws a warning, and I need it to log an error inst...
  • tristaanogre's avatar
    9 years ago

    Internally in the script extension, the code executed is the Files.Compare method.  A lot of the extension does the heavy lifting of manipulating the word documents in order to cleanly execute Files.Compare.  Files.Compare by default returns a warning message whenever the two files do not match. The script extension uses that default:

      var tempResult = Files.Compare(fullName1, fullName2);

    So, the extension will always log a warning.  However, the extensions compare method returns a boolean so that WordDocs.Compare returns true if the files match or false if they do not:

     

      return tempResult && picEquals; 

    What you can do is wrap your code with some if/then logic... something like this (untested):


    Sub CompareWordDocs(file1, file2)
          Dim CompareResult
          CompareResult = Call WordDocs.Compare(file1, file2, 2)
          if !CompareResult
               Log.Error("The files are different")
    End Sub

    I'm not a very good VBScript coder so I'm sure my syntax above needs work but hopefully you get the idea.