cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Submit your abstract to the call for content for Discovery Summit Americas by April 23. Selected abstracts will be presented at Discovery Summit, Oct. 21- 24.
Discovery is online this week, April 16 and 18. Join us for these exciting interactive sessions.
Choose Language Hide Translation Bar
MarkJohnson
Level II

How to reference a table variable inside a table variable

After creating the first two variables, I'd like to make my angleRefY and my angleRefX variables be offset from zeroX and zeroY by a static number. I've tried to do this a few different ways as you can see below. 

MarkJohnson_0-1586552035759.png

 

The only way that produced a number was this script, but then the variable becomes 6 instead of QQ+1, so they still aren't linked.

dt << Set Table Variable("TT", dt:QQ + 1);

Does anyone know how this could be done? Ideally zeroX = some number, zeroY = some number, angleRefX = zeroX + some number, and angleRefY = zeroY + some number as a dynamic reference.

1 ACCEPTED SOLUTION

Accepted Solutions
txnelson
Super User

Re: How to reference a table variable inside a table variable

A Table Variable is just a saved string of characters.  Even if your value of QQ would have worked, your IF statement could never be true.

if ( dt:TT == 51, show("success"), show("didn't quite work"));

dt:TT can never have the value of 51.  All table variables end up as character strings, so the IF statement was ever going to work, it would have to be written as:

if ( dt:TT == "51", show("success"), show("didn't quite work"));

Here is the documentation from the Scripting Guide

Table Variables
Table variables are for storing a single text string value, such as “Notes”. To understand how
variables work, first get its existing value by sending a Get Table Variable message:
	dt = Open( "$SAMPLE_DATA/Solubility.jmp" );
	dt << Get Table Variable( "Notes" );
		"Chemical compounds were measured for solubility in different solvents. This
		table shows the log of the partition coefficient (logP) of 72 organic
		solutes in 6 aqueous/nonpolar systems."
Now change the existing value of the string using Set Table Variable and then use Get
Table Variable again to check that the string has been updated:
	dt << Set Table Variable( "Notes", "Solubility of chemical compounds" );
	dt << Get Table Variable( "Notes" );
		"Solubility of chemical compounds"
The following example adds two new table variables to a data table:
	dt = Open( "$DOCUMENTS/Big Class.jmp" );
	myvar = "This is my version of the JMP Big Class sample data.";
	dt << Set Table Variable( "key1", myvar );
	dt << Set Table Variable( "key2", myvar );
Notice that setting the value creates a new variable only if one by the given name does not
already exist. If you add two table variables with the same name, only one variable is created.

You could possibly do what you want using a Table Script, but you would have to first set the table variable QQ and then run the table script that would update TT

Jim

View solution in original post

6 REPLIES 6
txnelson
Super User

Re: How to reference a table variable inside a table variable

Here is a simple example.  Your code was close, just needed to understand that all Table Variables are character, and also, all you need to do to reference a table variable is to use :QQ, since the dt is already the object of the message.

names default to here(1);
dt=new table("Example", add rows(3),new column("Sample", values([1,2,3])));
dt << new table variable("QQ", 42 );
dt << New Table Variable("TT", num(:QQ) + 1);
Jim
MarkJohnson
Level II

Re: How to reference a table variable inside a table variable

That creates a static offset, I should have been more clear that the goal is a dynamic offset. For example, if QQ gets reassigned to 43, the goal is to have TT resolve to 44 all by itself.

 

Here is an adaptation of your code that should print whether the variable is actually dynamic or not. 

names default to here(1);
dt=new table("Example", add rows(3),new column("Sample", values([1,2,3])));
dt << new table variable("QQ", 42 );
dt << New Table Variable("TT", eval(num(:QQ) + 1));
wait(0);
dt << set table variable("QQ", 50);
if ( dt:TT == 51, show("success"), show("didn't quite work"));
txnelson
Super User

Re: How to reference a table variable inside a table variable

A Table Variable is just a saved string of characters.  Even if your value of QQ would have worked, your IF statement could never be true.

if ( dt:TT == 51, show("success"), show("didn't quite work"));

dt:TT can never have the value of 51.  All table variables end up as character strings, so the IF statement was ever going to work, it would have to be written as:

if ( dt:TT == "51", show("success"), show("didn't quite work"));

Here is the documentation from the Scripting Guide

Table Variables
Table variables are for storing a single text string value, such as “Notes”. To understand how
variables work, first get its existing value by sending a Get Table Variable message:
	dt = Open( "$SAMPLE_DATA/Solubility.jmp" );
	dt << Get Table Variable( "Notes" );
		"Chemical compounds were measured for solubility in different solvents. This
		table shows the log of the partition coefficient (logP) of 72 organic
		solutes in 6 aqueous/nonpolar systems."
Now change the existing value of the string using Set Table Variable and then use Get
Table Variable again to check that the string has been updated:
	dt << Set Table Variable( "Notes", "Solubility of chemical compounds" );
	dt << Get Table Variable( "Notes" );
		"Solubility of chemical compounds"
The following example adds two new table variables to a data table:
	dt = Open( "$DOCUMENTS/Big Class.jmp" );
	myvar = "This is my version of the JMP Big Class sample data.";
	dt << Set Table Variable( "key1", myvar );
	dt << Set Table Variable( "key2", myvar );
Notice that setting the value creates a new variable only if one by the given name does not
already exist. If you add two table variables with the same name, only one variable is created.

You could possibly do what you want using a Table Script, but you would have to first set the table variable QQ and then run the table script that would update TT

Jim
Byron_JMP
Staff

Re: How to reference a table variable inside a table variable

Jim,

Thanks for that tip on table variables being character. That's a definite, pull your hair out if you don't know it, problem to run into.

 

one other little addition.  if,  dt:QQ="51";  then wrapping dt:QQ, like this, num(dt:QQ) will return 51 rather than "51". But if dt:QQ isn't numeric, then it will return missing. 

 

The alternative to this, which will work,

if ( dt:TT == "51", show("success"), show("didn't quite work"));

 is something like this, which will work if dt:TT is numeric

if ( num( dt:TT ) == 51, show("success"), show("didn't quite work"));
JMP Systems Engineer, Health and Life Sciences (Pharma)
MarkJohnson
Level II

Re: How to reference a table variable inside a table variable

Well there ya go. If it only can store string values, it seems pretty clear that I won't be able to have it be a dynamic reference. Running the table script makes sense. It is just one extra click too, not bad. Thank you for the help!!
Byron_JMP
Staff

Re: How to reference a table variable inside a table variable

you could always just throw the variable into the global name space and reference that.

JMP Systems Engineer, Health and Life Sciences (Pharma)