Forum: Ruby How to open a file with win32ole

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
73700e119917433681f2e8f3e4369f74?d=identicon&s=25 Li CN (alex-osu3)
on 2008-10-13 21:48
Hi all,

I want to open a file via win32ole. I find the method 'Open' there but
always get error feedback. I wonder if anyone can give me a hand.

Thanks,

Li

########################
require 'win32ole'
fs=WIN32OLE.new('SAPI.SpFileStream')
count=1
fs.ole_methods.each{|m|
    print count,"\t"
    print m,"\t"
    print m.return_type_detail,"\t"
    puts
    count+=1
}

file='c:/test.txt'
fs.open(file)###line14 here


win32ole2.rb:14:in `method_missing': open (WIN32OLERuntimeError)
    OLE error code:800C0005 in <Unknown>
      <No Description>
    HRESULT error code:0x80020009
      Exception occurred.  from win32ole2.rb:14
>Exit code: 1
Ba608f20b6707017d9812b9b3f1406e3?d=identicon&s=25 gpy good (gpygood)
on 2008-10-14 03:25
try this:

require 'win32ole'
fs=WIN32OLE.new('SAPI.SpFileStream')

p fs.ole_method("open").params

file='c:/test.txt'


fs.Open(file,2) #least two params
fs.write("data")
fs.Close
73700e119917433681f2e8f3e4369f74?d=identicon&s=25 Li CN (alex-osu3)
on 2008-10-14 16:53
gpy good wrote:
> try this:
>
> require 'win32ole'
> fs=WIN32OLE.new('SAPI.SpFileStream')
>
> p fs.ole_method("open").params
>
> file='c:/test.txt'
>
>
> fs.Open(file,2) #least two params
> fs.write("data")
> fs.Close

Hi bud,

Thank you very much for the tips. It is so sweet.

From this example I guess that if a method is on the list but the object
cannot receive it, most likely that more parameters need to be passed
in.

One more question: How am I supposed that I should pass number 2 in the
script above, instead of other numbers like, 0, 1, 10,...?


Li
This topic is locked and can not be replied to.