EyeOpener has asked for the wisdom of the Perl Monks concerning the following question:

I'm running into a snag with Win32::OLE. I'm trying to script something for CuteFTP's Transfer Engine, and one of its properties requires arguments. I know I have to use the SetProperty() method to set the values, but the question is: what's the syntax for retrieving the current value of properties with arguments? I would have thought I could use the hash syntax, and this would work (this is a snippet of my script, but runnable as-is):

use Win32::OLE qw(in with); use Win32::OLE::Const 'CuteFTPPro'; my $ftp = Win32::OLE->new('CuteFTPPro.TEConnection', 'Close'); print "autoclosemethod is currently ", $ftp->{Option}{AutoCloseMethod} +, "!\n"; $ftp->SetProperty('Option', "AutoCloseMethod", 1); print "autoclosemethod is now ", $ftp->{Option}{AutoCloseMethod}, "!\n +";

It doesn't. The output varies whether I have warnings enabled:

D:\>perl test.pl autoclosemethod is currently ! autoclosemethod is now ! D:\>perl -w test.pl Win32::OLE(0.1601) error 0x8002000e: "Invalid number of parameters" in METHOD/PROPERTYGET "Option" at test.pl line 6 Win32::OLE(0.1601) error 0x8002000e: "Invalid number of parameters" in PROPERTYPUT "Option" at test.pl line 6 autoclosemethod is currently Use of uninitialized value in print at te +st.pl line 6. ! Win32::OLE(0.1601) error 0x8002000e: "Invalid number of parameters" in METHOD/PROPERTYGET "Option" at test.pl line 8 Win32::OLE(0.1601) error 0x8002000e: "Invalid number of parameters" in PROPERTYPUT "Option" at test.pl line 8 autoclosemethod is now Use of uninitialized value in print at test.pl +line 8. !

I can't tell if this is a problem with my Win32::OLE calls, or if I'm misinterpreting the CuteFTP docs. CuteFTP says the Option property is used both to set and retrieve settings, but they don't give examples of retrieving settings (and their examples are all VBScript anyway). I'm a novice with Win32::OLE, and I don't know of any other OLE applications that have properties requiring arguments, so I can't test this with anything else.

Can anyone tell me the proper syntax for this with Win32::OLE? Better yet, does anyone happen to have working CuteFTP script examples? (Might as well shoot high :-)

Thanks!

Replies are listed 'Best First'.
Re: Win32::OLE properties
by Grygonos (Chaplain) on Mar 31, 2004 at 20:05 UTC

    have you tried $ftp->Option->{AutoCloseMethod} or maybe  $ftp->Option(AutoCloseMethod)->{Value}?!? If I were writing it that's how I'd have made it work...

    Check the Excel OLE docs and look at the item property of the Worksheets collection. It is a property.. but for example .. say you want to get the code name from the first sheet in your worksheets collection... you could write it as $worksheets->Item(x)->{CodeName} using item without { } Normally you would code it as $worksheets(x)->{CodeName} however, but that's OT.

    <edit> also throw use strict; in at the top of your script, it will help you become more efficient in your development (at least I think so)<edit>

    anyhow hope that's what fixes it for you...

    Grygonos
      Thanks, your Excel example helped to get me the answer! The proper syntax is $ftp->Option(AutoCloseMethod), as in:

      use Win32::OLE qw(in with); use Win32::OLE::Const 'CuteFTPPro'; my $ftp = Win32::OLE->new('CuteFTPPro.TEConnection', 'Close'); print "autoclosemethod is currently ", $ftp->Option(AutoCloseMethod), +"!\n"; $ftp->SetProperty('Option', "AutoCloseMethod", 1); print "autoclosemethod is now ", $ftp->Option(AutoCloseMethod), "!\n";

      That got me the output I needed:

      D:\>perl -w test.pl autoclosemethod is currently 0! autoclosemethod is now 1!

      Thanks for the quick help!