cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
JMP is taking Discovery online, April 16 and 18. Register today and join us for interactive sessions featuring popular presentation topics, networking, and discussions with the experts.
Choose Language Hide Translation Bar
zhouye0
Level II

Is there a way the replace Eval(Parse(Eval Insert())) when creating variable names on the go?

Everytime I try to create variables in loops, it has always been using Eval, Parse, and Eval Insert. An example is shown below

For(i=0 , i < N Table(), i++,

Eval(Parse(Eval Insert("Variable^i^")))

);

The method above works fine, but as scripts get huge, more and more variables and operations have to be put inside the quotation marks, which makes debugging really hard. Is there any other way to create variables on the go, other than the Eval, Parse, Eval Insert method?

1 ACCEPTED SOLUTION

Accepted Solutions
ian_jmp
Staff

Re: Is there a way the replace Eval(Parse(Eval Insert())) when creating variable names on the go?

This might give you a clue. Some (but, last time I checked, not all) of the display boxes have an lvalue that is subscriptable:

NamesDefaultToHere(1);

// Build a 'dynamic' UI . . .

n = 6;

lub = LineUpBox(NCol(1));

nebs = {};

For (i=1, i<=n, i++,

InsertInto(nebs, NumberEditBox(.));

lub << Append(nebs[i]);

);

nw = NewWindow("List of Number Edit Boxes", lub, ButtonBox("OK", OKscript));

// Get the user input values when 'OK' is hit . . .

OKscript =

Expr(

nw << closeWindow;

For(i=1, i<=n, i++, Print(nebs[i] << get))

);

View solution in original post

8 REPLIES 8
ian_jmp
Staff

Re: Is there a way the replace Eval(Parse(Eval Insert())) when creating variable names on the go?

JSL supports numerous design patterns, some perhaps non-obvious. Could you give a more specific example of when you want to 'create variables in a loop', that also indicates the next step of how you would actually want to use such variables?

zhouye0
Level II

Re: Is there a way the replace Eval(Parse(Eval Insert())) when creating variable names on the go?

An example would be, I want to create an equal amount of this below...

11852_pastedImage_2.png

for each data table opened, so the amount of Combo Boxes, or Button Boxes created each time would vary on the amount of data tables opened.

And I have a variable assigned to each Combo box and button box for tracking purposes (and it needs to be there). So this leaves me no choice but to create a variable using Eval, Parse, and Eval Insert each time so that I have a variable tracking each Combo/Button Box that I create.

Eval(

  Parse(

  Eval Insert(

  "

  if(DTopened > 1,

  lbBB^i^ = Border Box(

  H List Box(

  dtListBox^i^ = Combo Box( listofdtnames ),

  Picture Box( img ),

  Combo Box( test ),

  BBox^i^ = Button Box( \!"Fetch Temperature\!" )

  )

  );

  "

            )

       )

   );

Is there a way to eliminate Eval, Parse, and Eval Insert and use something simpler?

Edit: I forgot to mention that the code is inside a for loop with variable "i" looping

ian_jmp
Staff

Re: Is there a way the replace Eval(Parse(Eval Insert())) when creating variable names on the go?

This might give you a clue. Some (but, last time I checked, not all) of the display boxes have an lvalue that is subscriptable:

NamesDefaultToHere(1);

// Build a 'dynamic' UI . . .

n = 6;

lub = LineUpBox(NCol(1));

nebs = {};

For (i=1, i<=n, i++,

InsertInto(nebs, NumberEditBox(.));

lub << Append(nebs[i]);

);

nw = NewWindow("List of Number Edit Boxes", lub, ButtonBox("OK", OKscript));

// Get the user input values when 'OK' is hit . . .

OKscript =

Expr(

nw << closeWindow;

For(i=1, i<=n, i++, Print(nebs[i] << get))

);

zhouye0
Level II

Re: Is there a way the replace Eval(Parse(Eval Insert())) when creating variable names on the go?

Hi Ian,

Thanks for pointing that the method of storing the displayBoxes into a list. I'm going to attempt those for Combo Boxes instead of Number Edit Boxes. By the way. Do you know where I can get a full list of display boxes that are subscriptable?

ian_jmp
Staff

Re: Is there a way the replace Eval(Parse(Eval Insert())) when creating variable names on the go?

I'm not aware of any such list, unfortunately. But you will soon know if it doesn't work!

I remember that (with JMP 10 I think), the 'SliderBox{}' was not subscriptable, so I had to do a little more work. This may have been fixed subsequently.

pmroz
Super User

Re: Is there a way the replace Eval(Parse(Eval Insert())) when creating variable names on the go?

If you have lots of variables maybe a list or matrix structure would help?  Or an associative array?

pmroz
Super User

Re: Is there a way the replace Eval(Parse(Eval Insert())) when creating variable names on the go?

I just had to do something similar and an array of expressions did the trick.  No getting away from eval though.  Here's a code example that illustrates things:

tb_expr = {};

tb_expr[1] = expr(hlistbox(textbox("1: "), textbox("First one")));

tb_expr[2] = expr(hlistbox(textbox("2: "), textbox("Second one")));

tab_expr = expr(

     test_tab << replace(1, "Test Tab", eval(tb_expr[index]));

);

nw = new window("test",

     hlistbox(button box("One",

                index = 1;

                tab_expr;

           ),

           button box("Two",

                index = 2;

                tab_expr;

           ),

     ),

     test_tab = tab box("Test Tab", eval(tb_expr[1]))

);

zhouye0
Level II

Re: Is there a way the replace Eval(Parse(Eval Insert())) when creating variable names on the go?

The only way I know how to get rid of eval (as of now) is using Ian's method, which makes debugging a bit better. Because I realized that errors that happen inside the things that I eval dont show up in the log, which makes debugging a little bit harder...