From: MikkelFJ Date: 2002-08-05T01:57:38+09:00 Subject: Re: win32ole and excel "Masaki Suketa" wrote in message news:200208041151.UAA28336@smtp2.nifty.ne.jp... > > However, my long term problem with WIN32OLE remains: > > components with an optional parameter seems to not be working. I got this > > document object with a Save method taking a filename and an optional second > > parameter. This won't execute. > > Could you show me the script which is not working? First of all the following Visual Basic script does result in a file: Set mdm = CreateObject( "MDM.Document.2") mdm.Save ("testfile.mdd") I cannot do the same with Ruby. The problem is with the Save method of the following interface (only the essential part shown): [ odl, uuid(C95896B9-F8E6-4CFE-B960-6A667FFA6658), helpstring("IDocument Interface"), dual, oleautomation ] interface IDocument : IMDMLabeledObject { [id(0x0000000b), propget, helpstring("property CurrentVersion")] .... HRESULT Versions([out, retval] IVersions** pVal); [id(0x00000022), helpstring("method Save")] HRESULT Save([in, optional] VARIANT destination); .... }; Here is the script and the runtime results. I think this has something to do with optional parameters. I did the same test about a year ago. I did not have problems using VB script for example. require 'win32ole' mralias = WIN32OLE.new('mrAliasMap.Mapper') puts mralias.CreateAlias("this is a long name").Name mdm = WIN32OLE.new('MDM.Document.2') mdm.Save ('testfile.mdd') puts 'done' The yields C:\test\w32\win32ole\sample>ruby test.rb thialona test.rb:6:in `method_missing': Save (WIN32OLERuntimeError) OLE error code:80070057 in HRESULT error code:0x80020009 Undtagelse opstod from test.rb:6 The first output line indicates that another COM component is working (truncating a long name). The Com error is partly in danish: "Undtagelse opstod" which translates to "an exception occurred". Althoug the error says "method missing" this isn't true. If I change the Save to use two parameters I get a different error; require 'win32ole' mralias = WIN32OLE.new('mrAliasMap.Mapper') puts mralias.CreateAlias("this is a long name").Name mdm = WIN32OLE.new('MDM.Document.2') mdm.Save ('testfile.mdd', 0) puts 'done' This yields C:\test\w32\win32ole\sample>ruby test.rb thialona test.rb:6:in `method_missing': Save (WIN32OLERuntimeError) OLE error code:0 in HRESULT error code:0x8002000e Ugyldigt antal parametre from test.rb:6 The danish message is know: "Ugyldigt antal parametre" which translates to "Illegal number of parameters". So clearly the save method is recognized. If I change the Save method to a non-existing name "Safe", I get the following output: C:\test\w32\win32ole\sample>ruby test.rb thialona test.rb:6:in `method_missing': Unknown property or method : `Safe' (WIN32OLERunt imeError) HRESULT error code:0x80020006 Ukendt navn from test.rb:6 The danish text "Ukendt navn" translates to "Unknown name". Mikkel