- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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.
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.
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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"));
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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"));
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: How to reference a table variable inside a table variable
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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.