Hi. I'm wondering if there's a convenient method for a button box to somehow know where it lies within a lineup box. My specifics:
JMP Pro 16.2.0
I have a script that creates a window with a LineUp box. In each cell, there's a button box that I want to perform a different action, based on which column the button appears in. For example:
Names Default to Here(1);
list = {"cat", "dog", "mouse", "kangaroo", "sloth"};
list2 = {"meow", "bark", "squeak", "hop", "zzz"};
lub = LineUpBox(NCol(2), Spacing(5));
For(i=1, i<=NItems(list), i++,
tb = TextBox(list[i]);
bb = ButtonBox(list2[i],
//Insert code for the button to somehow identify which button it is within lub.
Speak(list2[i])
);
lub << Append(tb);
lub << Append(bb);
);
New Window("Test", lub);If I run the script as is, I get:

But when I click on any of the buttons, I get the error:
"Subscript Range in access or evaluation of 'list2[ /*###*/i]' , list2[/*###*/I]"
I understand this error because there's no way for the button box to recall the value of "i" when executed. My question: is there a method I could use that would allow the button box to "self-identify" where it lies in the line up box when pressed, and use that value as the list2 index in the button script?
I'm currently using JSL Quotes and the Substitute command to create the buttons. In that case I write the contents of the For loop as a JSL Quote and substitute in the value of i, then Eval(Parse()). This is clunky though, and I'm wondering if there's a better way, like a "bb << Get Location" or "bb << Count Siblings" command. These commands don't exist of course, but perhaps there's another technique?
Thanks!
Thanks! This is an even more elegant solution.
As an answer to the OP's original question, the answer is yes and it's rather simple. Here is an example:
Names Default to Here(1);
list = {"cat", "dog", "mouse", "kangaroo", "sloth"};
list2 = {"meow", "bark", "squeak", "hop", "zzz"};
lub = LineUpBox(NCol(2), Spacing(5));
For(i=1, i<=NItems(list), i++,
tb = TextBox(list[i]);
bb = ButtonBox(list2[i], <<SET function=""></SET>Hi Jarmo. The Eval Insert/Eval Expr/Parse Combo is similar to the JSLQuote/Substitute/Parse Combo that I'm currently using. But the other solutions you provided were exactly the kind of thing I was looking for. Thanks!
I don't know of any direct method of getting the location, but you could calculate the "location" or you could insert the knowledge to button with Insert one expression into another using Eval Insert, Eval Expr, Parse, and Substitute . You can also use << get button name to get text of the button; or << prev sib with correct reference to get text in the text box; you could "hide" the text in tooltip of button (or index)... and there are many more options, depending on what you want to do and how you want to do it.
View more...