| Store | Cart
Lists » pdk

RE: vbscript converter runs without producing any output

From: Ovod-Everett, Toby <to6...@att.com>
Mon, 26 Mar 2012 10:18:18 -0800
-----Original Message-----
From: pdk-...@listserv.activestate.com
[mailto:pdk-...@listserv.activestate.com] On Behalf Of Eric
Promislow
Sent: Monday, March 26, 2012 9:00 AM
To: p...@listserv.activestate.com
Subject: Re: vbscript converter runs without producing any output

> On 3/24/2012 10:04 PM, Phillip Richcreek wrote:> >
myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/confi
guration/smtpusessl") = True
>      $myMail->Configuration->Fields->SetProperty("Item",
'http://schemas.microsoft.com/cdo/configuration/smtpusessl', 1);

My first stab at manually translating the code from the VBScript would
probably be something like this:

$myMail->{Configuration}->{Fields}->Item("http://schemas.microsoft.com/c
do/configuration/smtpusessl")->{Value} = 1;

Here is my rationale:
* Hash syntax (->{Configuration}) when using Win32::OLE indicates a
Property
* Method syntax (->Configuration) when using Win32::OLE indicates a
Method.  Win32::OLE will automatically try looking for a Property as
well, but I prefer to be a little more explicit.
* I looked on MSDN for the CDO.Message definition and found
http://msdn.microsoft.com/en-us/library/ms526453(v=exchg.10).aspx which
documents the IMessage Interface.
* Configuration is listed as a Property, so I used ->{Configuration}
* Configuration returns an object that implements IConfiguration, so I
then tracked down the IConfiguration interface and it listed Fields as a
Property, so I used ->{Fields}
* Fields is a ADODB.Fields object, so I tracked that down.
* Now we get to the level of Collections, which are always a little
funky in my experience.   Item is technically a Property, but because it
requires an index parameter, we'll use the method call syntax.
Furthermore, if you look at something like
http://msdn.microsoft.com/en-us/library/windows/desktop/ms675103(v=vs.85
).aspx, you'll see that there's this whole "implicit default property"
and Value seems to be that property a lot.  All I know is that much of
the time I can get away without Value, but that things tend to behave
cleaner (fewer Win32::OLE objects floating around when I really want to
look at a bare value) if I use it.  

Part of the problem is that VB and VBA and VBScript do a lot of
"under-the-covers" work that simplifies the syntax (no syntactic
difference between properties and method calls, a lot of implicit stuff
so that one can dismiss with stuff that must be made explicit in other
languages), and so working straight from VBScript can be iffy and
writing a translator is not necessarily straightforward.  I tend to use
VBScript examples as a starting point for what I'm trying to do, but go
straight to the MSDN references for the components to verify how I want
to write that code in Perl.

Finally, I test every single return value, use Win32::OLE->LastError() a
lot, etc.

Also, when setting values, one must sometimes use Win32::OLE::Variant
and Variant(VT_foo, $data) in order to ensure proper coercion to an
acceptable variant type.  For instance, if the above doesn't work, I
would next try substituting Variant(VT_BOOL, 1) in place of 1 (thus
making sure it gets a Boolean instead of a digit).

Warning!  I did not actually find a box with CDO on it and start testing
- the above is just the syntactic magic that seems to work for me the
best, but your mileage may vary!


Toby Ovod-Everett
AT&T Alaska Information Services
907.264.7620
This e-mail and any files transmitted with it are AT&T property, are
confidential, and are intended solely for the use of the individual or
entity to whom this email is addressed. If you are not one of the named
recipient(s) or otherwise have reason to believe that you have received
this message in error, please notify the sender and delete this message
immediately from your computer. Any other use, retention, dissemination,
forwarding, printing, or copying of this e-mail is strictly prohibited.
_______________________________________________
PDK mailing list
P...@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Recent Messages in this Thread
Phillip Richcreek Mar 25, 2012 05:04 am
Eric Promislow Mar 26, 2012 04:59 pm
Ovod-Everett, Toby Mar 26, 2012 06:18 pm
Messages in this thread