Forum Discussion

lleppert's avatar
lleppert
Contributor
8 years ago
Solved

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 instead. Anybody know how to do this? Here is my current code:

 

Sub CompareWordDocs(file1, file2)
      Call WordDocs.Compare(file1, file2, 2)
End Sub

 

Thanks!

  • 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.

8 Replies

  • tristaanogre's avatar
    tristaanogre
    Esteemed Contributor

    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.

    • lleppert's avatar
      lleppert
      Contributor

      That worked! Thanks so much. Here is the syntax if anybody else needs it:

       

      Sub CompareWordDocs(file1, file2)
           Dim CompareResult
           CompareResult = WordDocs.Compare(file1, file2, 1)


           If CompareResult = "True" then

                Log.Message("File " & file2 & " matches.")
           Else
                Log.Error("File " & file2 & " has changed.")       
           End If


      End Sub

      • shilpawdhw's avatar
        shilpawdhw
        Occasional Contributor

        Hi Can anyone help me

         

        I executed above script . I am getting an error Object require wordDocs. I am using test complete 12