Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Win32::OLE Type for VB's "As Single"

by davemabe (Monk)
on Jan 20, 2005 at 15:10 UTC ( #423708=perlquestion: print w/ replies, xml ) Need Help??
davemabe has asked for the wisdom of the Perl Monks concerning the following question:

I am using a Win32 COM API that has a function that takes several parameters and assigns values to the variables. Here is the code in VB that I'm trying to convert to Perl.
Sub GetData(Number As Long, Prices() As Single, OtherDataPoints() As S +ingle)
Here is the pseudo code I am trying to use to make it work:
my $object = Win32::OLE->new('ClassID'); # this works correctly. my $number = 1; my $prices; my $others; my $returnValue = $object->GetData($number,$prices,$others); # always fails with Win32::OLE(0.1701) error 0x80020005: "Type mismatc +h" in argument 2
Does anyone know what variant type I need to assign to $prices and $others that is equivalent to VB's "As Single"? I've tried several of the variant types found in the Win32::OLE::Variant perldoc, but so far I'm striking out.

Dave

Comment on Win32::OLE Type for VB's "As Single"
Select or Download Code
Re: Win32::OLE Type for VB's "As Single"
by demerphq (Chancellor) on Jan 20, 2005 at 15:32 UTC

    Just a totally off the top of my head guess, but what happens if you change it to:

    my $prices=0.0; my $others=0.0;

    I was just thinking that Win32::OLE() might have trouble telling how an undef SV should be converted.

    ---
    demerphq

      Same error :-( Thanks, though.
Re: Win32::OLE Type for VB's "As Single"
by gellyfish (Monsignor) on Jan 20, 2005 at 15:44 UTC

    In the VB code Prices() and OtherDataPoints() are arrays - you should be using @prices and @others in your Perl code and assign them appropriately if required.

    /J\

Re: Win32::OLE Type for VB's "As Single"
by guha (Priest) on Jan 20, 2005 at 15:57 UTC

    I would look into using variants.

    use Win32::OLE::Variant; my $number = 1; my $var_number = Variant(VT_R4, $number); $object->GetData($var_number,etc etc)

    HTH

      Shame on me not reading the OP properly!!

      my $number = Variant(VT_I4, 1);; my $prices = Variant(VT_R4 | VT_ARRAY, [1,10], 1); # Index 0 .. 9 my $others = Variant(VT_R4 | VT_ARRAY, [1,5], 1); # Index 0 .. 4 my $returnValue = $object->GetData($number,$prices,$others);
      If this does not work I would try to "OR" the by_reference constant for the array statements like
      Variant(VT_R4 | VT_ARRAY | VT_BYREF, [1,5], 1);

      I have no possibility to test this myself, so please regard this as the shot in the dark it is. But since you don't seem to have reached a working solution, I offer you this straw....

Re: Win32::OLE Type for VB's "As Single"
by holli (Monsignor) on Jan 20, 2005 at 16:06 UTC
    i think this should do it (untested quick shot):
    my $object = Win32::OLE->new('ClassID'); # this works correctly. my $number = 1; my $prices = []; my $others = []; my $returnValue = $object->GetData($number,$prices,$others);

    holli, regexed monk
      Good suggestions, but they all produce the same error. :-(
Re: Win32::OLE Type for VB's "As Single"
by injunjoel (Priest) on Jan 20, 2005 at 19:05 UTC
    Greetings all,
    This is a total shot in the dark but have you looked into using Math::BigFloat or just bignum?
    Just a thought...

    -InjunJoel
    "I do not feel obliged to believe that the same God who endowed us with sense, reason and intellect has intended us to forego their use." -Galileo
Re: Win32::OLE Type for VB's "As Single"
by traveler (Parson) on Jan 20, 2005 at 20:20 UTC
    Single means single precision. GetData is different for differnet objects, and I do not know what kind of object you have, but I think this might work:
    my $object = Win32::OLE->new('ClassID'); # this works correctly. my $number = 1; my @prices; my @others; my $returnValue = $object->GetData($number,\@prices,\@others);

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://423708]
Approved by gellyfish
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (9)
As of 2014-07-23 06:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (133 votes), past polls