5 Replies Latest reply: May 15, 2014 9:57 AM by Nick Osdale-Popa RSS

    Programming Monarch

    Donny Stogsdill

      I am running version 5 pro.  I'm trying to write a VB script to open multiple files, apply a model and then export the table to an excel document.  The problem I'm having is when i run the script it errors out when creating the COM object.  Heres the line of code:

      Set MonarchObj = CreateObject("Monarch32")

       

      Any suggestions are greatly appreciated.

        • Programming Monarch
          Data Kruncher

          Hi Donny,

           

          Odds are that you've done this already, but in addition to your Set statement, you should  [font="courier"]Dim MonarchObj as Object  /font[/quote]and, what's likely missing now, set a reference to the Monarch object library in your project.

           

          HTH,

          Kruncher

          • Programming Monarch
            Donny Stogsdill

            Thanks for the reply.  When i dim the variable as an object it errors out.  Here's the code I have:

             

            Private Sub Monarch_Load()

            Dim MonarchObj

            Dim openfile, openmod

            Dim t

            Set MonarchObj = CreateObject("Monarch32")

            t = MonarchObj.SetLogFile("C:     mpmonarch.log")

            openfile = MonarchObj.SetReportFile("Z:invval_04_18_07INVVALs18.txt")

            If openfile = True Then

                 Openmod = MonarchObj.SetModelFile("J:Inventory Valuation ReportMonarch Modelinvval_model.mod")

                      If openmod = True Then

                           MonarchObj.ExportTable("C:     mp     est.xls")

                      End If

            End If

            MonarchObj.CloseAllDocuments

            MonarchObj.Exit

            End Sub

             

            This is basically verbatim from the Programmers guide except It doesnt allow me to declare the variables as an object or boolean.

            Any thoughts?

            • Programming Monarch
              Nick Osdale-Popa

              You have two commands that don't have fully qualified parameters.

               

              Change your code:[quote][font="courier"]t = MonarchObj.SetLogFile("C:     mpmonarch.log")

              openfile = MonarchObj.SetReportFile("Z:invval_04_18_07INVVALs18.txt")[/font][/quote]To

              [font="courier"]t = MonarchObj.SetLogFile("C:     mpmonarch.log", False)

              openfile = MonarchObj.SetReportFile("Z:invval_04_18_07INVVALs18.txt", False)[/font][/quote]For SetLogFile:

              True = new messages are appended to the log file

              False = the previous contents of the log file are deleted

               

              For SetReportFile:

              True = the report is added to the list of open reports

              False = all other reports are closed before opening the new report.

               

               

              Everything else should work just fine.

               

              FYI: For a decent VBScript editor/debugger, take a look at [url="http://www.vbsedit.com/"]VBSEdit[/url]

               

              You are correct, VBScript doesn't allow you to declare the TYPE of variables, you can only DIM them.

               

              Hope that helps!

              • Programming Monarch
                Donny Stogsdill

                Nick,

                That fixed it.  Thanks very much for your help.

                • Programming Monarch
                  Nick Osdale-Popa

                  Super!

                   

                  Glad to help out.   smile.gif[/img]