Get variable in a macro

    Get variable in a macro

    Hi people,

    I wonder how I can get a variable's value in a macro ?

    I tried:

    PHP Source Code

    1. // does not work
    2. $myvariable=activesheet()->range("myvariable")->value;


    PHP Source Code

    1. // does not work
    2. $myvariable=retrieve_value("myvariable");


    when I use a combobox and that target is a "ouptutVariable" variable, then the following works:

    PHP Source Code

    1. $myvariable=retrieve_value("ouptutVariable");


    any idea ?
    laloune

    Post hoc, non est propter hoc
    I'm not a php programmer, but generally I'd think, if "myvariable" could contain >1 value (var with combobox -> selection of a consolidated element -> maybe it loads then also the children internally...?!?), it might be an array for php in turn, or point to one. Did you try to qualify more exact, which member of the potential myvariable-array you want to adress? Respectively, at which place inside of the range you want to place the var content, in case that the variable stores only one value?

    But that is just a first idea, if useless: forget it ;-))
    Hi keinelimitz,

    right, that works fine

    the only problem I saw by the time is that this statement is only for form elements available, for instance if you have a combobox whose name "mycombobox" is, then you can set or get the value of this combobox with :

    PHP Source Code

    1. define_variable('mycombobox','value');
    2. $valueretrieved=retrieve_variable('mycombobox');


    with named ranges that is another story. If I define a named range, let's say : "myrange" => A1
    assuming A1 contains "hello world!, to get the value of this name :

    PHP Source Code

    1. $valueofmyrange=ActiveWorkbook()->names->item('myrange')->value;
    2. // returns "hello world!"


    but to set it ?

    PHP Source Code

    1. ActiveWorkbook()->names->item('myrange')->value='mynewvalue';
    2. // does not seem to work
    laloune

    Post hoc, non est propter hoc
    Regarding named ranges: since it's internally actually "named formulas" (a range just being a specific formula like =A1), what you need to define in a macro to change the "value" of the name is to change the "refers_to" property:

    PHP Source Code

    1. function SetRange() {
    2. // Create named formula macroname1. Set it to =10.
    3. ActiveWorkbook()->names->add("macroname1")->refers_to = "=10";
    4. }


    Wether the name "macroname1" already exists doesn't matter here; if it doesn't, it is created, if it does, its property is changed.
    =macroname1
    would then return the value "10".
    Hi,
    thanks for solving this issue here.
    I have some kind of a beginner question.
    If I didn't know about the existence of the function retrieve_variable() where would I look to find it?
    Of course I am interested to see a list of functions I can use for writing php based macros in Jedox.

    Post was edited 1 time, last by “rhagedorn” ().