Using a script, how do I set the text of a table script in a button box in a journal file?Using a script, I need to construct a completely self-contained journal file with button boxes that reproduce data tables. In the production application, there will be many headings (each representing a part), and each heading will have several button boxes beneath it, each showing a different data table associated with the part. Because of the complex calculations that go into constructing the data tables, I am constructing them using functions. My intent would be to distribute ONLY the journal file to users.
I have constructed a skeletal example using the Baltic.jmp sample data table. The function "SmallTables()" returns the table script as text. But I can't find a way to enter that text in the script boxes for the button boxes in the journal file. Any help would be greatly appreciated.
SmallTables = Function( {k},
dt = Open( "$Sample_Data/Baltic.jmp" );
dt_Small = dt << Subset( Rows(), Columns( Column( k ) ), Output Table Name( "Small" ) );
Close( dt, NoSave );
tblScript = dt_Small << Get Script;
result = Char( Name Expr( tblScript ) );
);
jrn = New Window( "Table Test", Outline Box( "Title" ) );
For( k = 1, k <= 5, k++,
jrn << Append( BB = Button Box( "Small Table " || Char( k ), Set Script( SmallTables( k ) ) ) )
);Re: Using a script, how do I set the text of a table script in a button box in a journal file?Thank you so much for the reference to that article! It's a very clear explanation with nice examples. It is very helpful.
Re: Using a script, how do I set the text of a table script in a button box in a journal file?The trick is making sure the sub-expression is inserted before it is evaluated. This JSL Cookbook article might help:
Insert one expression into another using Eval Insert, Eval Expr, Parse, and Substitute
Re: Using a script, how do I set the text of a table script in a button box in a journal file?What a nice example! In my project, though, I need to construct hundreds of data tables, several for each of many parts. This is why I am using functions to construct the data tables (hopefully no beginning user will ever see that script!). I'm afraid that your suggestion would result in too many windows being open at once. But, for a manageable number of data tables, your concept is very nice! I am sure that I'll have occasion to use it.
Thank you so much for your help.
Re: Using a script, how do I set the text of a table script in a button box in a journal file?Thank you so much! That works perfectly in my "big" script. I was fixated on the idea that the result of my function was a text representation of the script, and, as such, should be entered in the button box script dialog. I'm still unclear as to why that doesn't work, but using the Name Expr function and Substitute, as you demonstrated, works perfectly.
By the way, in my real-life application, the loop is required because I need to construct different tables. I have a large number of parts, and the script constructs several data tables, with scripts, that are unique to each part. That script takes a little while to run, so it's great to be able to run that script to create a self-contained journal file.
Thank you again for setting me on the right path!
Re: Using a script, how do I set the text of a table script in a button box in a journal file?I use self-contained journal files for demos and training, making them easy to share. Links to close individual sections and to clean up everything keeps things moving. The script below creates a basic example journal; once you run it, you should see a journal with links in it. Right click on each and select Edit > Edit Script to see how they are constructed. I use 'Copy Table Script' often to populate these. Putting this codes in functions is a good idea, but be mindful of it looking more like black magic to beginning users who try to explore your journal.

Note that I normally make journals interactively, not using a script like this.
names default to here(1);
//Open data tables temporarily so we can copy their scripts
dtIrisTemp = open("$Sample_Data/Iris.jmp");
dtBigClassTemp = open("$Sample_Data/Big Class.jmp");
//Use Eval(EvalExpr()) so the actual scripts for the data table are saved in
//the journal.
Eval( Eval Expr(
journal = New Window( "A Journal", <<JOURNAL></JOURNAL>
Re: Using a script, how do I set the text of a table script in a button box in a journal file?If you will be using one table, I wouldn't open and close it for each function call. I'd open the table, build the window, with the for loop then close the table.
Try this.
SmallTables = Function( {k},
dt = Open( "$Sample_Data/Baltic.jmp" );
dt_Small = dt << Subset( Rows(), Columns( Column( k ) ), Output Table Name( "Small" ), Invisible );
Close( dt, NoSave );
_xx = dt_Small << Get Table Script Names;
dt_Small << Delete Scripts(_xx);
tblScript = dt_Small << Get Script;
wait(0);
Close( dt_Small , NoSave);
NameExpr(tblScript)
);
jrn = New Window( "Table Test", Outline Box( "Title" ) );
For( k = 1, k <= 5, k++,
_xx = SmallTables(k);
Eval(Substitute(Expr(jrn << Append( BB = Button Box( "Small Table " || Char( k ), Set Script( _scr ) ) )),
Expr(_scr), NameExpr(_xx) ) )
);Re: Using a script, how do I set the text of a table script in a button box in a journal file?