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

Hi,

I'm trying to get some information from SPSS using Win32::OLE. My problem is you need to pass a variant array of strings to the function, which is filled and returned. I'm using the following code:

use Win32::OLE; $spssapp = Win32::OLE->GetActiveObject('SPSS.Application'); $data = $spssapp->Documents()->GetDataDoc(0); my $nvars = $data->GetVariableColumnWidths($cwidths);
This code works OK in SPSS Basic. In Perl the GetVariableColumnWidths function succeeds (LastError = 0 and $nvars returns the correct value) but nothing is returned in $cwidths.

I've experimented with creating $cwidths with Win32::OLE::Variant first using all of the following

my $cwidths = Variant(VT_BTSR | VT_ARRAY, ""); my $cwidths = Variant(VT_BTSR | VT_ARRAY | VT_BYREF, ""); my $cwidths = Variant(VT_VARIANT | VT_ARRAY, ""); my $cwidths = Variant(VT_VARIANT | VT_ARRAY | VT_BYREF, "");
none of which work. Can anyone help?

Thanks,
Steve

Replies are listed 'Best First'.
Re: Win32
by BrowserUk (Patriarch) on Oct 11, 2002 at 02:02 UTC

    You need to specify some dimensions for your array I think. From the Win32::OLE docs

    To create a SAFEARRAY variant, you have to specify the VT_ARRAY flag i +n addition to the variant base type of the array elemnts. In this cas +es DATA must be a list specifying the dimensions of the array. Each e +lement can be either an element count (indices 0 to count-1) or an ar +ray reference pointing to the lower and upper array bounds of this di +mension: my $Array = Win32::OLE::Variant->new(VT_ARRAY|VT_R8, [1,2], 2) +; This creates a 2-dimensional SAFEARRAY of doubles with 4 elements: (1, +0), (1,1), (2,0) and (2,1).

    Cor! Like yer ring! ... HALO dammit! ... 'Ave it yer way! Hal-lo, Mister la-de-da. ... Like yer ring!
      Thanks for the reply. I'm afraid I'm getting the same result with a safearray:
      my $cwidths = Variant(VT_BSTR|VT_ARRAY, [1,371]);
      has the same effect (LastError = 0, nothing in $cwidths) and
      my $cwidths = Variant(VT_BSTR|VT_ARRAY|VT_BYREF, [1,371]);
      produces an "invalid callee" OLE error. Also as I don't know how many variables there are I actually need a dynamic array - is it possible to create one of these? Thanks, Steve