in reply to Re: Win32::OLE::Variant Array
in thread Win32::OLE::Variant Array

Can't call method "Get" on unblessed reference ...

It seems the return value of BLPGetHistoricalData() is not a Perl object (i.e. a blessed reference), but rather just a regular reference. What it exactly is largely depends on the method being called, but unfortunately, the API description you posted isn't all that detailed in that respect, and I don't have the Bloomberg ActiveX control installed, so I can't test myself either...

Best approach is probably to dump the returned data structure, e.g. using Data::Dumper, to figure out what it actually is (maybe an arrayref holding a list of variant objects — but that's merely a guess):

use Data::Dumper; # ... print Dumper $bbData;

___

(<meta> not wanting to sound patronizing, but please use the [reply] link at the right margin of the node you're replying to. In that case I would have gotten a message that there's a reply... (when people don't report back within a day or so, I don't always check for responses any longer). </meta>)

Replies are listed 'Best First'.
Re^3: Win32::OLE::Variant Array
by kevind0718 (Scribe) on Sep 07, 2007 at 16:36 UTC
    Hello: I was finally able to get a run on the live Bloomberg station. And got this out put.
    Error: 0 $VAR1 = [ [ [ bless( do{\(my $o = 27137740)}, 'Win32::OLE::Variant' ), '112.04' ] ], [ [ bless( do{\(my $o = 27137852)}, 'Win32::OLE::Variant' ), '113.23' ] ], [ [ bless( do{\(my $o = 27137964)}, 'Win32::OLE::Variant' ), '111.89' ] ], [ [ bless( do{\(my $o = 27138116)}, 'Win32::OLE::Variant' ), '113.89' ] ], [ [ bless( do{\(my $o = 27138268)}, 'Win32::OLE::Variant' ), '113.53' ] ], [ [ bless( do{\(my $o = 27138492)}, 'Win32::OLE::Variant' ), '112.98' ] ], [ [ bless( do{\(my $o = 27138604)}, 'Win32::OLE::Variant' ), '110.73' ] ], [ [ bless( do{\(my $o = 27138756)}, 'Win32::OLE::Variant' ), '112.64' ] ] ]; end
    which is great progress! I see prices.
    what does the (my $o = 27138604) represent?
    Is there a way this could be interputed as a date?
    many thanks
    kd

      Nice to see you're making progress.  Have you tried printing the values like I suggested in my other post? E.g., for the given data structure:

      for my $e (@$bbData) { my $d = $e->[0]; print "date: $d->[0]\n"; # presuming it's a date... print "price: $d->[1]\n"; }

      (where $bbData is the variable you dumped (which I suppose is the data structure being returned by BLPGetHistoricalData()))

      It shouldn't be necessary to reverse engineer those "(my $o = 27138604)"s. The idea behind the dump was just to get an idea of the general structure of the data returned. From what you got, you can tell that the first element in every innermost array is a Win32::OLE::Variant object. In other words, if it's a scalar-type variant (like VT_DATE), you should be able to just print it, as if it were a string (the object is automagically being stringified).

        brilliant! your code worked perfect. got dates and prices.
        many thanks. here is the code so others do not have to suffer with VB

        use Data::Dumper; use Win32::OLE; use Win32::OLE::Variant; $blpData = Win32::OLE->new('Bloomberg.Data.1') or die "can NOT load t +he blpData" ; #print $blpData->Timeout . "\n"; $aSec = Variant(VT_BSTR, "IBM Equity"); #@tmpArray = ("PX_Last"); $aFields = Variant(VT_ARRAY|VT_BSTR, 1 ); $aFields->Put(0, "PX_Last"); $sDate = Variant(VT_DATE, "2007/08/01"); $eDate = Variant(VT_DATE, "2007/08/10"); $bbData = Variant(VT_EMPTY, 1); $bbData = $blpData->BLPGetHistoricalData($aSec, $aFields, $sDate, $e +Date); print "Error: " . Win32::OLE->LastError . "\n"; #print "Array Size: " , $bbData->Dim . "\n"; #print "Returned: " . $bbData->Get(0) . "\n"; # print Dumper $bbData; for my $e (@$bbData) { my $d = $e->[0]; print "date: $d->[0] " . " Price: $d->[1] \n" ; #foreach $tmp (@aDim) { # print $tmp # } print "end" ;
Re^3: Win32::OLE::Variant Array
by Anonymous Monk on Aug 20, 2007 at 20:32 UTC

      Maybe it's not interpreting your date range correctly (so your start and end data effectively map to the same (invalid/default) day...). Have you tried specifying the date strings in a different format when initialising VT_DATE? The docs seem to suggest something like "July 1,2007" or "July 1 2007".  Other than that, I'm afraid I can't help...