Subscribe Bookmark RSS Feed

Using variables to specify scale

phungtnguyen

Community Member

Joined:

Jun 23, 2011

Instead of using constants to specify the scale in a plot, I want to use variables to do so.

This section of code works

Dispatch(

            {},

            "1",

            ScaleBox,

            {Min( mn ), Max( mx ), Inc( mi ), Minor Ticks( nminor ),

            Add Ref Line( mr, Solid, "Black" ), Show Major Grid( nmaj )}

        )

However, I'm unable to specify Scale ( "Log" ) using a variable.

This section of code does not work

Dispatch(

            {},

            "1",

            ScaleBox,

            {Scale( ms ), Min( mn ), Max( mx ), Inc( mi ), Minor Ticks( nminor ),

            Add Ref Line( mr, Solid, "Black" ), Show Major Grid( nmaj )}

        )

where ms="Log"

suggestions appreciated

1 REPLY
XanGregg

Staff

Joined:

Jun 23, 2011

There are some places where JMP (unfortunately) only accepts a literal value, not a variable. The ugly work-around is to use JMP meta-programming features like Substitute(). For example:

ms = "Log";

cmd = Substitute(Expr(Dispatch(

            {},

            "1",

            ScaleBox,

            {Scale( SCALEVALUE ), Min( mn ), Max( mx ), Inc( mi ), Minor Ticks( nminor ),

            Add Ref Line( mr, Solid, "Black" ), Show Major Grid( nmaj )}

        )), Expr(SCALEVALUE ), ms);

Eval(cmd); // if you had a complete expression

Substitute() is replacing the token SCALEVALUE with the value of ms.

Eval Insert() is another option but works on strings instead of expressions, so you'll have to Parse() the string before calling Eval().