Hello all,
I have a simple example script. Can somebody explain me what are the scopes for the variables here and why it works one way and not another?
Here's the initial script:
Names default to here(1);
Clear Globals();
x="Variable";
exprA = Expr(Write("Here is variable: "||x));
exprB = Expr(
dt1 = Open( "$SAMPLE_DATA/Big Class.jmp" );dt1 << OnClose(exprA));
exprB;The idea is that I open table and give it an expression it needs to run when it's closed. Expression evaluates and changes (not in this example) some variables from the script.
The way it is written it doesn't work - nothing happens, but in my real script it just says it can't find a reference.
Okay, let's try to make ExprA global:
Names default to here(1);
Clear Globals();
x="Variable";
::exprA = Expr(Write("Here is variable: "||x));
exprB = Expr(
dt1 = Open( "$SAMPLE_DATA/Big Class.jmp" );dt1 << OnClose(exprA));
exprB;Now it does see the expression, but it still doesn't work, because now it doesn't see the x variable.
Ok, let's make x global too:
Names default to here(1);
Clear Globals();
::x="Variable";
::exprA = Expr(Write("Here is variable: "||x));
exprB = Expr(
dt1 = Open( "$SAMPLE_DATA/Big Class.jmp" );dt1 << OnClose(exprA));
exprB;Now it works:
Scriptable[]Here is variable: Variable
// Close Data Table: Big Class
Close( "Big Class" );
The question: why does it work this way and doesn't work the initial way? I looked to me it should've worked.
I don't like using global variables in this script - any other way to make it work?