by default, when JMP creates a variable, like your xMat etc. the variable will remain until it is changed. And, if on the first run of your code, the required variable hasn't been created, when you are asking for it in your code, it will not have a value to provide the program, and then some calculations will not be able to be run. However, if later in the script, the variable is set, it will remain set until deleted of changed. Therefore, when you run the script for a second time, and the code gets to the point where in the first run of the script, it could not find the required variable, this time it will find it, because it was set at a later time in the code during the last run of the script.
I found a possible place where this could have happened. You were setting the variable dt after activities on the data table were being done. I moved the line of code further up in the script, so that may get the code to work on a first run. I also placed a "Clear Symbols()" as the first line of the script. This will clear out all variables in the code as the script begins. This will ensure that the variable values referenced will have to have been created in this run of the code, since all of the values from the last run have been erased. Try the code and see if it works.
Clear Symbols();
Names Default To Here( 1 );
ramex_value = "";
w = New Window( "Frame size X", // opens a window with a title and this content...
<<Return Result,
Border Box( top( 20 ), bottom( 20 ), Left( 20 ), Right( 20 ), // window dressing
V List Box( // V and H lists nest to organize the display boxes
H Center Box( Text Box( "Frame size X" ) ), // a second title, centered
Spacer Box( size( 1, 20 ) ), // a little vertical space
H List Box( Text Box( "Frame size X: " ), framex = Number Edit Box( "." ) ), // data entry
Spacer Box( size( 1, 10 ) ), // a little vertical space
H Center Box( // center the button
Button Box( "Create graph", // this script runs when the button is pressed...
framex_value = framex << get;
dt = Current Data Table();
Column( dt, "X coordinate" ) << data type( Numeric ) << Modeling Type( Continuous ) << Format( Best, 12 );
dt << New Column( "New Y", Numeric, Nominal, Width( 5 ), Formula( Round( Y coordinate ) ) );
dt << select where( :New Y != 50503 );
dt << delete rows;
dt << New Column( "Normalized", Numeric, Continuous, Width( 10 ), Precision( 7 ), Formula( IntenCD / Col Max( IntenCD ) ) );
// Determine X Matrix
xMat = Matrix( 76200 - (framex_value / 2) ) |/ Matrix( 76200 - (framex_value / 2) ) |/ Matrix( 76200 + (framex_value / 2) ) |/
Matrix( 76200 + (framex_value / 2) );
// The yMat is static
yMat = [1, 0.92, 0.92, 1];
// The overall delta
overallDelta = Col Max( dt:Normalized ) - Col Min( dt:Normalized );
//The delta between the lines
withinOrangeDelta = Col Max(
If( dt:X coordinate > (76200 - (framex_value / 2)) & dt:X coordinate < (76200 + (framex_value / 2)),
dt:Normalized,
.
)
) - Col Max( dt:Normalized ) - Col Min( dt:Normalized ) + 1;
Col Min( If( dt:X coordinate > (76200 - (framex_value / 2)) & dt:X coordinate < (76200 + (framex_value / 2)), dt:Normalized, . ) );
// Graph Builer and Delta display
gb = dt << Graph Builder(
Size( 534, 456 ),
Show Control Panel( 0 ),
Variables( X( dt:X Coordinate ), Y( dt:Normalized ) ),
Elements( Points( X, Y, Legend( 5 ) ) )
);
Report( gb )[FrameBox( 1 )] << Add Graphics Script(
Pen Color( "orange" );
Pen Size( 2 );
Line( xmat, ymat );
// Add the results to the chart
Text( Boxed, {75000, .94}, "Overall Delta = " || Char( Format( overallDelta, 7, 4 ) ) );
Text( Boxed, {75000, .93}, "Within Frame Delta = " || Char( Format( withinOrangeDelta, 7, 4 ) ) );
);
Report( gb )[AxisBox( 2 )] << Min( .91 );
w << closeWindow;
)
)
)
)
);
Jim