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

Hi all,

I'm having a beast of a time accessing something in Perl that works beautifully in VBA, and I think it's a syntax issue. I'm trying to simply change a string of text to be red.

The VBA code is this, based on "expression.CharProps(CellIndex)":

vsoChar.CharProps(visCharacterColor) = 2

In Perl, I expected this to work:

$vsoChars->CharProps(visCharacterColor)= 2;

But I get a 'can't modify non-lvalue subroutine call' error. I've tried all sorts of things and nothing will work.

Thanks in advance!

Josh

Replies are listed 'Best First'.
Re: OLE Visio syntax problem
by 7stud (Deacon) on Jun 02, 2011 at 02:39 UTC

    This is essentially what you are trying to do:

    use strict; use warnings; use 5.010; sub greet { say 'hello'; } greet() = 10;

    Does that make any sense?

    You probably need to do something like:

    my $href = { visCharacterColor => 2, }; vsoChars->CharProps($href);

    In perl, often times the getter and setter will be the same function--if the function has an argument, it will set the value; and if the function is called with no argument, then it will return the value. Check the docs to see what type the argument to CharProps() should be.

      Thanks for the feedback!

      In this case, I think my problem is that I'm using parentheses where I shouldn't. The "CharProps" is a 'property' in OLE, and that is usually accessed like so:

       $vsoChars->{Begin} = 2;

      For this property, though, there are different parts you can access, so there is an additional 'cell index' that needs to be passed in to access the correct property. 'visCharacterColor' is a constant, it's really just the number 1. I can't figure out how to get the cell index (1) passed so I can set what I want (the color) to 2 (red)...

      I've looked into the perl OLE documentation I could find and lots of web searching but no luck...so far...

      Thanks!
Re: OLE Visio syntax problem
by 7stud (Deacon) on Jun 02, 2011 at 22:06 UTC

    See if you can figure out anything from this perlmonks tutorial: tut

      In case anyone had the same type of question, I solved my problem with another review of the OLE documentation...For properties with arguments, you need to use "SetProperty". In my case it is this...

      $vsoChars->SetProperty('CharProps', 1, 2)

      Thanks!