check if Win32OLE still available

R

Reinhart Viane

[Note: parts of this message were removed to make it a legal post.]

In ruby i use these commands:



application = WIN32OLE.new('MSProject.Application')

application.visible = TRUE

application.FileOpen(filepath)

project = application.ActiveProject



now if the user closes MS Project, any call to application.function returns:

The RPC server is unavailable.



Which off course, I think, is logic.

How do I test if the application is still available?



Regards and thx

Reinhart
 
R

Reinhart Viane

Hey,

I have tried this but it gives me an error.
I was wondering how I can catch that its' not with '' or nil

Thx again!

-----Original Message-----
From: (e-mail address removed) [mailto:[email protected]]
Sent: woensdag 25 augustus 2010 18:10
To: ruby-talk ML
Subject: Re: check if Win32OLE still available

Which off course, I think, is logic.

How do I test if the application is still available?

call some method on it, perhaps?
 
C

Charles Calvert

I have tried this but it gives me an error.
I was wondering how I can catch that its' not with '' or nil

When you call a method after the application has been closed, does it
throw an exception? If so, you could catch the exception and check
the error to see if it's a result of the closing of the app.
 
R

Reinhart Viane

Hello,

I'm getting back on this.
I do receive an error, however, it seems I cannot catch it.
It does not give me back empty or nil. Maybe there is another method to
catch that error?

-----Original Message-----
From: Charles Calvert [mailto:[email protected]]
Sent: woensdag 25 augustus 2010 20:57
To: ruby-talk ML
Subject: Re: check if Win32OLE still available

I have tried this but it gives me an error.
I was wondering how I can catch that its' not with '' or nil

When you call a method after the application has been closed, does it
throw an exception? If so, you could catch the exception and check
the error to see if it's a result of the closing of the app.
 
M

Masaki Suketa

I'm getting back on this.
I do receive an error, however, it seems I cannot catch it.

What is the error you received?
It does not give me back empty or nil. Maybe there is another method to
catch that error?

How about catching WIN32OLERuntimeError?

begin
...(your script)
catch WIN32OLERuntimeError
...(catching error)
end

Regards,
Masaki Suketa
 
R

Reinhart Viane

This is the error:

Error: #<WIN32OLERuntimeError: unknown property or method `ActiveSelection'
HRESULT error code:0x800706ba
The RPC server is unavailable.

Where can I find more info on that catching?
Is it possible to use in a if clause (to let the script continue or go to
another script)?

Thx already!


-----Original Message-----
From: Masaki Suketa [mailto:[email protected]]
Sent: maandag 20 september 2010 10:23
To: ruby-talk ML
Subject: Re: check if Win32OLE still available

I'm getting back on this.
I do receive an error, however, it seems I cannot catch it.

What is the error you received?
It does not give me back empty or nil. Maybe there is another method to
catch that error?

How about catching WIN32OLERuntimeError?

begin
...(your script)
catch WIN32OLERuntimeError
...(catching error)
end

Regards,
Masaki Suketa
 
M

Masaki Suketa

This is the error:

Error: #<WIN32OLERuntimeError: unknown property or method `ActiveSelection'
HRESULT error code:0x800706ba
The RPC server is unavailable.

Where can I find more info on that catching?
http://rubylearning.com/satishtalim/ruby_exceptions.html

Is it possible to use in a if clause (to let the script continue or go to
another script)?

No. You must use begin rescue end to catch WIN32OLERuntimeError exception.
If you want to let the script continue, write the script like following.

is_ok = true
begin
obj.ActiveSelection
rescue WIN32OLERuntimeError
is_ok = false
end
if (is_ok)
...
continue script non exception occurred.
else
...
continue script when WIN32OLERuntimeError occurred.
end

Regards,
Masaki Suketa
 
R

Reinhart Viane

Excellent! Thank you.

-----Original Message-----
From: Masaki Suketa [mailto:[email protected]]
Sent: maandag 20 september 2010 13:50
To: ruby-talk ML
Subject: Re: check if Win32OLE still available

This is the error:

Error: #<WIN32OLERuntimeError: unknown property or method `ActiveSelection'
HRESULT error code:0x800706ba
The RPC server is unavailable.

Where can I find more info on that catching?
http://rubylearning.com/satishtalim/ruby_exceptions.html

Is it possible to use in a if clause (to let the script continue or go to
another script)?

No. You must use begin rescue end to catch WIN32OLERuntimeError exception.
If you want to let the script continue, write the script like following.

is_ok = true
begin
obj.ActiveSelection
rescue WIN32OLERuntimeError
is_ok = false
end
if (is_ok)
...
continue script non exception occurred.
else
...
continue script when WIN32OLERuntimeError occurred.
end

Regards,
Masaki Suketa
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,067
Latest member
HunterTere

Latest Threads

Top