The below code works from a script wondow, and is basically 3 different ways to change a column formula.
When I run the same code from a custom JMP toolbar it will crash on ::dt:helloworld << set formula ("5");
why is this? shouldn't the behavior be identical?
open("$SAMPLE_DATA/Amplitude 100.jmp");
dt = datatable("amplitude 100");
obj = new column("helloworld");
:helloworld << set formula("3");
dt :helloworld << set formula ("4");
::dt:helloworld << set formula ("5");
caption("Hello World");
There are a couple of issues. The first is that you need to isolate your code from being impacted by other scripts, etc. that are being run.
Names Default to Here( 1 );
does that.
Secondly, you were making incomplete references, and you were probably not seeing errors when you were running them, because their values were in the global memory space, and you had not eliminated them.
Third, in the context of your code, the statement
obj <SPAN class="token operator">=</SPAN> <SPAN class="token function">new column</SPAN><SPAN class="token punctuation">(</SPAN><SPAN class="token string">"helloworld"</SPAN><SPAN class="token punctuation">)</SPAN><SPAN class="token punctuation">;</SPAN>
would not have a reference, since OBJ had not been defined in your code.
The code below works on my system
Names Default To Here( 1 );
dt = Open( "$SAMPLE_DATA/Amplitude 100.jmp" );
dt << New Column( "helloworld", character, set each value( "5" ) );
Caption( "Hello World" );