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

Button Box list - which button have I just clicked on?

I'm creating a lined-up list of button boxes within a window (I don't know how many of them there are going to be until the script is actually run) as shown below.  Obviously when I click on any one of the buttons, I need it to perform an action.  That action however will be dependent upon the number of the button - so I need to know which button I've clicked... and unless I'm overlooking something obvious, I can't see an easy way to determine that.  Can anyone tell me how I can do it, please?

Expr_Do_Something = expr(/* What can I type in here that will tell me which button I've pressed? */);

lub = lineupbox(ncol(4));

for(i=1, i<=12, i++, lub<< append(Button Box("Button "|| char(i), Expr_Do_Something)));

nw= new window("Test", lub);

Unfortunately there are reasons I can't do this with a different control like a combo box, which would simply return the item I select.  It seems to me that what I really need is something like a "Current Active Button() << get button name" command, but I assume there isn't one - am I right?

Many thanks for any suggestions received.

[Footnote: I've just spotted a related discussion between "Volf", "Stig" and myself from a couple of years back which may well help with this at https://communities.sas.com/message/42855#42855, but I'll leave the question open anyway in case there are any other approaches to this]

Message was edited by: David Q/R

1 ACCEPTED SOLUTION

Accepted Solutions
ms
Super User (Alumni) ms
Super User (Alumni)

Re: Button Box list - which button have I just clicked on?

I expect which_button to be the same (13 in this case) regardless of which button that is clicked.

Although I "feel" that there should be a simpler way, the only solution I got to work is via some string manipulation and parsing of the lub<<append() commands. An example:

Do_Something = "print(lub[Buttonbox(^i^)]<<get button name)";

lub = Lineup Box( N Col( 4 ) );

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

  Eval(

  Parse(

  "lub << append( Button Box( \!"Button " || Char( i ) || "\!"" || ", " ||

  Eval Insert( Do_Something ) || "))"

  )

  )

);

nw = New Window( "Test", lub );

View solution in original post

4 REPLIES 4
pmroz
Super User

Re: Button Box list - which button have I just clicked on?

I would add a variable assignment before calling expr_do_something.  Then inside of expr_do_something you would check this variable.

Expr_Do_Something = expr(/* What can I type in here that will tell me which button I've pressed? */);

lub = lineupbox(ncol(4));

for(i=1, i<=12, i++, lub<< append(Button Box("Button "|| char(i), which_button = i; Expr_Do_Something)));

nw= new window("Test", lub);

ms
Super User (Alumni) ms
Super User (Alumni)

Re: Button Box list - which button have I just clicked on?

I expect which_button to be the same (13 in this case) regardless of which button that is clicked.

Although I "feel" that there should be a simpler way, the only solution I got to work is via some string manipulation and parsing of the lub<<append() commands. An example:

Do_Something = "print(lub[Buttonbox(^i^)]<<get button name)";

lub = Lineup Box( N Col( 4 ) );

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

  Eval(

  Parse(

  "lub << append( Button Box( \!"Button " || Char( i ) || "\!"" || ", " ||

  Eval Insert( Do_Something ) || "))"

  )

  )

);

nw = New Window( "Test", lub );

Re: Button Box list - which button have I just clicked on?

I suspected as much - and I'll almost certainly end up doing something of the kind.  I often do find myself solving problems like this by setting them up as text and then parsing them, so it's reassuring to know that I'm not missing something obvious.

Many thanks!

barasztamas
Level I

Re: Button Box list - which button have I just clicked on?

I'm not sure this is still relevant for you, but I think I've found a more straightforward way to deal with this problem:

Expr_Do_Something = expr(this << Get Button Name() );
lub = lineupbox(ncol(4));
for(i=1, i<=12, i++, lub<< append(Button Box("Button "|| char(i), << set Function(Function({this}, Expr_Do_Something)))));