4 Replies Latest reply: May 15, 2014 9:54 AM by Stephen Reid RSS

    Keeping monarch persistant

    Stephen Reid

      Hi all


      I know this topic was posted recently but I wanted to start a new post.  My question is in regards to the monarch_launch code that was posted on the earlier post.


      I have tried time and time again to get this to work but have never been successfull.  When I run the program on my PC it calls monarch_launch successfully then recognises monarch isn't running.  It then opens monarch and also opens my report and model but when the monarch_launch sub finishes monarch closes down and the program crashes when it tries to monarchobj.closealldocuments because monarchobj is no longer running.  I have also found that the monarchobj.isactive returns 0 whether monarch is running or not.


      I found a way around this some time ago by placing a switch in the code.  When the switch is on monarch keeps running and when it is turned off monarch closes.


      It would just be nice to it without the switch and understand why this is not working.


      Thanks in advance for any help


      Stephen Reid

        • Keeping monarch persistant
          Nick Osdale-Popa

          Would you mind posting your code? I'd be happy to look through it for you.

          • Keeping monarch persistant
            Stephen Reid

            Thanks Nick


            Here's my code, it is almost exactly the same as the code posted by Gareth Horton.



            Private Sub wopgOpen()


                Monarch_Launch                   'Call the Monarch_Launch sub

                Do While IsServerActive()        'Keep checking to see if server is active

                    DoEvents                     'Allows you to do other tasks



                'Clean up by closing all open documents


                'Send Monarch the exit command


                'Destroy the object - completing a nice clean exit procedure

                Set Monarchobj = Nothing

            End Sub



            Sub Monarch_Launch()

                 Dim openfile, openmod As Boolean

                 Dim Setwin As Boolean

                 Dim serveron, Winsize As Integer



                 'Check to see if the server is active (Monarch is open)

                 serveron = IsServerActive()


                 'If server is not active then create it

                 If serveron = 0 Then

                      Set Monarchobj = CreateObject("Monarch32")

                 End If


                 'Set Monarch to open in the table window

                 Setwin = Monarchobj.SetFirstView("T")


                'Open the report and model file

                 openfile = Monarchobj.setreportfile("S:steve_r cmstock2003P09wopg9.txt", False)


                 If openfile = True Then


                    openmod = Monarchobj.setmodelfile("S:steve_rMonarchModelsWOPG.mod")


                 End If


            End Sub



            Function IsServerActive()

                On Error GoTo NoServer

                If Monarchobj.IsActive > 0 Then     'Check to see if server is active

                    IsServerActive = 1

                End If

                Exit Function



                IsServerActive = 0                  'Trap the error when the server is inactive

                Exit Function

            End Function[/font][/quote]Thanks again



            • Keeping monarch persistant
              Data Kruncher

              Hi Stephen.


              There's only one line of code needed to make this work, and Gareth's example didn't have it either, so don't feel too frustrated. You need to declare your Monarch object as a global variable before the code for the subroutines.


              Simply add:


              Public Monarchobj as Object


              as the first line in your module.


              Worked for me.  Let us know if this resolves the problem.





              [size="1"][ October 09, 2003, 05:39 PM: Message edited by: Data Kruncher ][/size]

              • Keeping monarch persistant
                Stephen Reid



                Thanks Sandy.  I can't believe I kept missing that.  Greatly appreciated.