6 Replies Latest reply: May 15, 2014 9:53 AM by Gareth Horton RSS

    Monarch exception opening multiple reports through COM Server object

    Bret _

      Hello all.  When I call the Monarch32 object and try to open multiple reports (>30), Monarch throughs an exception and terminates   :mad:  .  Attached is the code I am using:

       

       

              Dim objMonarch As Object

              Dim openfile, openmod, t As Boolean

              Dim fileDialog As OpenFileDialog

       

       

              fileDialog = New OpenFileDialog

              fileDialog.InitialDirectory = "R:PRNTPACK"

              fileDialog.Title = "Select Reports..."

              fileDialog.Multiselect = True

              Dim result As DialogResult = fileDialog.ShowDialog

       

       

              If (result = DialogResult.OK) Then

                  objMonarch = CreateObject("Monarch32")

                  'objMonarch.Visible = False

       

                  For Each strFileName In fileDialog.FileNames

                      openfile = objMonarch.SetReportFile(strFileName, True)

                  Next

       

              End If

       

       

              If openfile = True Then

       

                  t = objMonarch.SetLogFile("C:Temp", False)

       

                  openmod = objMonarch.SetModelFile("R:TotalsReportsModelsEndpointTotals.xmod")

       

                  If openmod = True Then

                      objMonarch.CurrentSort = "Run#"

                      objMonarch.ExportTable("C:TempMonarch_NET_Test.csv")

       

                  End If

       

              End If

       

              objMonarch.CloseAllDocuments()

              objMonarch.Exit()

       

       

          End Sub

        • Monarch exception opening multiple reports through COM Server object
          Data Kruncher

          Hi Bret,

           

          I have a couple of ideas for you, but nothing that is proof as to why Monarch crashes with your code as shown.

           

          First, I would move the SetLogFile call to execute immediately after creating the Monarch object.

           

          Secondly, my normal approach to loading report files is setting the add flag for the SetReportFile call to False, and loading the rest of the reports with the flag set to True.

           

          Does this help at all?

           

          Kruncher

          • Monarch exception opening multiple reports through COM Server object
            Bret _

            I have made the changes to the code as you suggested, to no avail.  Here is the code as it is now:

             

            Dim objMonarch As Object

                    Dim openfile, openmod, t As Boolean

                    Dim fileDialog As OpenFileDialog

                    Dim strProcDate As String

                    Dim cnt As Integer

             

                    strProcDate = DateTime.Now.ToString("MMddyy")

             

             

                    fileDialog = New OpenFileDialog

                    fileDialog.InitialDirectory = "G:ATM Balancing" & strProcDate

                    fileDialog.Title = "Select Reports..."

                    fileDialog.Multiselect = True

                    Dim result As DialogResult = fileDialog.ShowDialog

             

             

                    If (result = DialogResult.OK) Then

             

                        objMonarch = CreateObject("Monarch32")

                        t = objMonarch.SetLogFile("G:ATM Balancingmonarch.log", True)

                        'objMonarch.Visible = False

             

                        For Each strFileName In fileDialog.FileNames

                            cnt = cnt + 1

                            If cnt = 1 Then

                                openfile = objMonarch.SetReportFile(strFileName, False)

                            Else

                                openfile = objMonarch.SetReportFile(strFileName, True)

                            End If

             

                        Next

             

                    End If

             

             

                    If openfile = True Then

             

             

                        openmod = objMonarch.SetModelFile("G:ATM BalancingModelsVisaNew.mod")

             

                        If openmod = True Then

                            objMonarch.CurrentFilter = "TRAN"

                            objMonarch.CurrentSort = "TRANAMT"

                            objMonarch.ExportTable("C:Tempvisa.xls")

             

                        End If

             

                    End If

             

                    objMonarch.WriteToLogFile("The Visa export was successfull!")

             

                    objMonarch.CloseAllDocuments()

                    objMonarch.Exit()

             

             

                End Sub

             

             

            and here is the subsequent error:

             

            An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in microsoft.visualbasic.dll

             

            Additional information: The server threw an exception.  :confused:

            • Monarch exception opening multiple reports through COM Server object
              Data Kruncher

              Well that's disappointing.    

               

              When stepping through the code line by line, which line throws the exception?

              • Monarch exception opening multiple reports through COM Server object
                Bret _

                openfile = objMonarch.SetReportFile(strFileName, True)

                 

                I'm getting these reports from a network share using a mapped drive.  Copying the files to the C: drive doesn't make any difference.  Still throws an exception.  Puzzling.

                • Monarch exception opening multiple reports through COM Server object
                  Data Kruncher

                  Does the MSDN page

                   

                  [url="http://msdn2.microsoft.com/en-us/library/af1y26ew"]http://msdn2.microsoft.com/en-us/library/af1y26ew[/url]  ( VS.80 ) .aspx

                   

                  provide any insight? I can't embed the URL in this post because of the parentheses in the URL. Take the extra spaces out too (required to upload this post properly).

                   

                  Coincidentally, you may want to review   [url="http://mails.datawatch.com/cgi-bin/ultimatebb.cgi?ubb=get_topic;f=1;t=001466;p=1#000007"]Nick's post from earlier today[/url]  discussing early and late binding.

                   

                  Unfortunately, I have no hands-on .NET experience, so my so-called advice may be somewhat limited here.

                  • Monarch exception opening multiple reports through COM Server object
                    Gareth Horton

                    Bret,

                     

                    Maybe you should dim StrFileName explicitly, then throw a msgbox in to see what it looks like before it gets passed to Monarch.

                     

                    Gareth

                     

                    Originally posted by Bret:

                    I have made the changes to the code as you suggested, to no avail.  Here is the code as it is now:

                     

                    Dim objMonarch As Object

                            Dim openfile, openmod, t As Boolean

                            Dim fileDialog As OpenFileDialog

                            Dim strProcDate As String

                            Dim cnt As Integer

                     

                            strProcDate = DateTime.Now.ToString("MMddyy")

                     

                     

                            fileDialog = New OpenFileDialog

                            fileDialog.InitialDirectory = "G:ATM Balancing" & strProcDate

                            fileDialog.Title = "Select Reports..."

                            fileDialog.Multiselect = True

                            Dim result As DialogResult = fileDialog.ShowDialog

                     

                     

                            If (result = DialogResult.OK) Then

                     

                                objMonarch = CreateObject("Monarch32")

                                t = objMonarch.SetLogFile("G:ATM Balancingmonarch.log", True)

                                'objMonarch.Visible = False

                     

                                For Each strFileName In fileDialog.FileNames

                                    cnt = cnt + 1

                                    If cnt = 1 Then

                                        openfile = objMonarch.SetReportFile(strFileName, False)

                                    Else

                                        openfile = objMonarch.SetReportFile(strFileName, True)

                                    End If

                     

                                Next

                     

                            End If

                     

                     

                            If openfile = True Then

                     

                     

                                openmod = objMonarch.SetModelFile("G:ATM BalancingModelsVisaNew.mod")

                     

                                If openmod = True Then

                                    objMonarch.CurrentFilter = "TRAN"

                                    objMonarch.CurrentSort = "TRANAMT"

                                    objMonarch.ExportTable("C:Tempvisa.xls")

                     

                                End If

                     

                            End If

                     

                            objMonarch.WriteToLogFile("The Visa export was successfull!")

                     

                            objMonarch.CloseAllDocuments()

                            objMonarch.Exit()

                     

                     

                        End Sub

                     

                     

                    and here is the subsequent error:

                     

                    An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in microsoft.visualbasic.dll

                     

                    Additional information: The server threw an exception.   :confused:  /b[/quote]