Subscribe Bookmark RSS Feed

Report and button box references

martin_snogdahl

Community Trekker

Joined:

Aug 17, 2016

Dear community,

I hope you can help with this. The example script below creates a table and opens the profiler platform. Additionally it appends two controls to the report. The functionality of the ‘Turn On’ button is to set the value of the Check Box to 1/true. The controls are added by using a reference to the profiler report, ‘PF’. Now, the problem arises when running the script twice in a row. By doing this, the ‘PF’ reference will be overwritten to refer to the newest report. When I use the ‘Turn On’ button on the old report, it now sets the value of the Check Box in the new report. Of course, this is not the behavior I want. I guess I must somehow use a unique reference for every report. Can anyone help? Thank you.

Table 1 = New Table( "Table 1",

  Add Rows( 1 ),

  New Column( "p1", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [2] ) ),

  New Column( "p2", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [3] ) ),

  New Column( "model",

  Numeric,

  "Continuous",

  Format( "Best", 12 ),

  Formula( :p1 ^ 2 + :p2 ^ 2 ),

  Set Selected

  ),

  Set Row States( [1] )

);

PF = Profiler(

  Y( :model ),

  Profiler(

  1,

  Term Value(

  p1( 2, Min( 1.9 ), Max( 2.1 ), Lock( 0 ), Show( 1 ) ),

  p2( 3, Min( 2.9 ), Max( 3.1 ), Lock( 0 ), Show( 1 ) )

  )

  )

);

Report(PF)["Prediction Profiler"] << Append(

  NewButton = Button Box("Turn On");

  //NewIndicator = Radio Box();

);

Report(PF)["Prediction Profiler"] << Append(

  CheckBox = Check Box("Item 1")

);

Report(PF)[Button Box(1)] << Set Script(

  CheckBox << Set(1)

);

4 REPLIES
txnelson

Super User

Joined:

Jun 22, 2012

The way that I handle such issues is to create the references to the different objects with different memory variables using substitute

Names Default to Here(1);

// Create a counter that initializes only the first time it is run, so it increments for each execution

if(isEmpty(counter)==1, counter = 0);

counter = counter + 1;

Eval( Substitute(Expr(

Report(PF)["Prediction Profiler"] << Append(

  __NewButton__ = Button Box("Turn On");

  //NewIndicator = Radio Box();

);),

Expr(__NewButton__), parse("NewButton" || char(counter)));

this will create NewButton1, NewButton2, etc. for each subsequent execution.

Jim
martin_snogdahl

Community Trekker

Joined:

Aug 17, 2016

So this did the trick, thank you.

Eval(

  Substitute(

  Expr(

  Report( PF )["Prediction Profiler"] << Append( _NewButton_ = Button Box( "Turn On" ) );

  Report( PF )["Prediction Profiler"] << Append( _CheckBox_ = Check Box( "Item 1" ) );

  _NewButton_ << Set Script(

  _CheckBox_ << Set( 1 )

  );

  ),

  Expr( __NewButton__ ), Parse( "NewButton" || Char( counter ) ),

  Expr(_CheckBox_), Parse( "CheckBox"  || Char( counter ))

  )

);

Craige_Hales

Staff

Joined:

Mar 21, 2013

Your example has a check box that is the next sibling of a button box, which means it is really easy for the button box to find the checkbox, if only the button box can find itself.  It can, if you use setFunction rather than set script.  Bold text, below.  The variable is gone.  You now have an anonymous function (not assigned to a JSL variable) that the button box can pass "this" to.  "this" is the button box, and the sibling of "this" is the checkbox.  The PF variable is still changed, but I'm not sure you need it.  It is possible for the function to crawl up through the <<parent chain to find the platform that holds the button.

Table 1 = New Table( "Table 1",

    Add Rows( 1 ),

    New Column( "p1", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [2] ) ),

    New Column( "p2", Numeric, "Continuous", Format( "Best", 12 ), Set Values( [3] ) ),

    New Column( "model", Numeric, "Continuous", Format( "Best", 12 ), Formula( :p1 ^ 2 + :p2 ^ 2 ), Set Selected ),

    Set Row States( [1] )

);

PF = Profiler(

    Y( :model ),

    Profiler(

        1,

        Term Value(

            p1( 2, Min( 1.9 ), Max( 2.1 ), Lock( 0 ), Show( 1 ) ),

            p2( 3, Min( 2.9 ), Max( 3.1 ), Lock( 0 ), Show( 1 ) )

        )

    )

);

Report( PF )["Prediction Profiler"] << Append(

    Button Box( "Turn On" );

  //NewIndicator = Radio Box();

);

Report( PF )["Prediction Profiler"] << Append( Check Box( "Item 1" ) );

Report( PF )[Button Box( 1 )] << Set Function( Function( {this}, (this << sib) << Set( 1 ) ) );

Craige
martin_snogdahl

Community Trekker

Joined:

Aug 17, 2016

Hi Craige

Thank you for this. The checkbox in this example was just for illustrating the behaviour. In my 'real' application the Button Box creates a journal from a report. So the issue was to have the button reference the right report window. Your solution might come in handy some other time. Thank You.