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

I'm still new at using Perl to drive OLE Automation. I'm to the point where I need to specify enumeration values as function arguments, and I am having problems stumbling onto the right syntax which makes everyone happy.

As for the particulars, I'm trying to get the RecordSet given a QueryDef. According to what I have found on MSDN, the format is:

Set recordset = object.OpenRecordset(type, options, lockedits)

where type, options, and lockedits are all enumerations defined as RecordsetTypeEnum, RecordsetOptionEnum, and LockTypeEnum defined in the Microsoft DAO 3.6 Object Library type library.

For onlookers, ActiveState's OLE Browser is cool for finding what classes, methods, properties, and enumerations are exposed through all installed type libraries.

Thanks for any insight that you can provide.


Replies are listed 'Best First'.
Re: Win32::OLE enumeration syntax?
by Anonymous Monk on Nov 23, 2003 at 06:06 UTC

    Okay, no takers thus far...

    Here's the basic question:

    use strict;
    my $querydef;
    my $recordset = $querydef->OpenRecordset(?, ?, ?, ?);
    Given that each ? is an enumeration already defined in the type library (described above), what is the correct syntax needed to keep the Perl interpreter happy?


      Browsing the Microsoft ActiveX Data Objects Recordset 2.7 Library using the perl OLE browser reveals, at the root level the Enum RecordTypeEnum, which has the values adCollectionRecord adSimpleRecord and adStructDoc (Numeric equivalents are 1,0 and 2). ).

      Getting these constants into perl is mildly tricky:

      >perl -e "; use Win32::OLE::Const 'Microsoft ActiveX Data Objects Reco +rdset 2.7 Library'; print adSimpleRecord . qq(\n) . adColl ectionRecord .qq(\n) . adStructDoc . qq(\n);" -- Results -- 0 1 2
      When I get stumped in situations like this, I usually just look up the actual numeric value and stick that in. And put the enum value name in a comment, so the reader knows what's going on.

      The 6th Rule of Perl Club is -- There is no Rule #6.