6 Replies Latest reply: May 15, 2014 9:55 AM by Michael Lane RSS

    how to catch errors while scripting

    Michael Lane

      Hi,

       

      I am automating some monarch exports with batch files. Many of the exports refer to a Microsoft Access database.  The problem is that when someone has the database open, the export will fail.  Any ideas on how I can handle this in the batch file?

       

      I'm using Monarch Pro 7.0 with Windows XP.

       

      Thanks,

      Michael Lane

        • how to catch errors while scripting
          Data Kruncher

          The JetExportTable and JetExportSummary methods return boolean values based on the result of the export in question. So a successful export returns TRUE; a failure returns FALSE.

           

          If you want to repeat the export until it works, try:

          [font="courier"]'more code...

          bSuccess = FALSE

          Do

             bSuccess = objMonarch.JetExportTable(strFile,strTable,intAppend)

             If Not bSuccess Then

                Msgbox "Exporting " & strTable & " failed."

             End If

          Until bSuccess=TRUE

          'more code...[/font][/quote]Alternatively, you could just stop the whole process once an export fails.

           

          [font="courier"]'more code...

          bSuccess = False

          bSuccess = objMonarch.JetExportTable(strFile,strTable,intAppend)

          If Not bSuccess Then

             Msgbox "Exporting " & strTable & " failed."

             Stop

          End If

          'more code...[/font][/quote]Quick ideas that aren't the most elegant things ever written, but should work for your needs as described. Let us know your progress.

           

          Kruncher

          • how to catch errors while scripting
            Michael Lane

            Thanks Kruncher.

            That would work for VB, but I'm trying to run monarch with shell scripting.  Say my batch file contains

            [font="courier"]

            @echo off

            call yesterday

            "C:Program FilesMonarchprogrammonarch.exe" /prj:"Q:ReportsAuto_Report.PRJ" /pxall

            rename Q:ReportsNewReport.xls Report%yesterday%.xls /font[/quote]The project exports in Auto_Report.prj export to a database and a file.  If the database is open, then the exports will fail, but I am not notified of this in any way.  Any shell scripting ideas on what to do about this?

            • how to catch errors while scripting
              Bruce _

              Michael

               

              I never try to update an shared access file, it always seems to fail. Not sure if this a fault with jet or something else.

               

              I use monarch to export to a file on my computer that is not shared, then use xcopy to copy the file to the network. This way I always have 2 copies of the access file in case of failure, and I do not need to worry if someone else is in or not.

               

              Just a thought, I am sure someone else has a better solution.

              • how to catch errors while scripting
                Data Kruncher

                Michael,

                 

                I understand your desire to keep your solution to the standard DOS-type batch file. But, as Bruce suggests, the command line parameters just won't give you the feedback, and therefore better process control, that the JetExport methods offer.

                 

                Give a [url="http://mails.datawatch.com/cgi-bin/ultimatebb.cgi?ubb=get_topic;f=1;t=001210;p=1#000000"]VBS script[/url] a try. If you're comfortable with the concepts of batch file development, I don't think that you'll find it too challenging.

                 

                I've seen people write some amazing batch files, but I think you'll find VBS much easier to handle. There are good VBScript tutorials to be found on the web.

                 

                Kruncher

                • how to catch errors while scripting
                  Nick Osdale-Popa

                  Michael,

                   

                  Like Kruncher, I do all my scripting in VBA. I'm not sure if the Monarch command sets an [url="http://www.robvanderwoude.com/errorlevel.html"]ERRORLEVEL /urlor not when it executes, but check that variable.

                   

                  Usually, any thing other than 0 means that the command failed. By checking that, you should be able to redirect your script accordingly.

                   

                  Hope this helps.

                   

                  [size="1"][ August 31, 2006, 09:30 AM: Message edited by: Nick Osdale-Popa ][/size]

                  • how to catch errors while scripting
                    Michael Lane

                    Thanks for all of the advice.  I tried ERRORLEVEL, but since the project export won't run, Monarch never returns, so there isn't an ERRORLEVEL generated, and the batch file does not continue running.

                     

                    I'll look into VBS scripts.  I'm familiar with VB.NET, so hopefully VBS shouldn't be too hard to implement. Thanks again!

                     

                    -Michael Lane