PDA

View Full Version : Keeping monarch persistant



Stephen Reid
October 9th, 2003, 10:19 AM
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

Nick Osdale-Popa
October 9th, 2003, 10:44 AM
Would you mind posting your code? I'd be happy to look through it for you.

Stephen Reid
October 9th, 2003, 11:10 AM
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
Loop

'Clean up by closing all open documents
Monarchobj.closealldocuments
'Send Monarch the exit command
Monarchobj.Exit
'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_rMonarchModelsWOP G.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

NoServer:
IsServerActive = 0 'Trap the error when the server is inactive
Exit Function
End FunctionThanks again

Stephen

Data Kruncher
October 9th, 2003, 12:49 PM
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.

Regards,
Sandy

[ October 09, 2003, 05:39 PM: Message edited by: Data Kruncher ]

Stephen Reid
October 16th, 2003, 09:38 AM
redface.gif

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

Stephen