Is there a way to input a multi-selection-checkbox of arbitrary length? (SOLVED)
11-09-2015, 06:08 PM (This post was last modified: 08-23-2018 10:25 PM by StephenG1CMZ.)
Post: #1
 StephenG1CMZ Senior Member Posts: 906 Joined: May 2015
Is there a way to input a multi-selection-checkbox of arbitrary length? (SOLVED)
In CHOOSE, I can choose just one from an arbitrary list using:
ASTEROIDS:={"1", "2",..." n"};
CHOOSE(CHS,"",ASTEROIDS);

But what I want is to able to select more than one, so that I could select several for plotting.

INPUT allows multiple items to be selected from check boxes, but the help seems to assume you know how many check boxes you have, and each is associated with a variable.
Using a list variable with check boxes compiles, but gives a run time error:
Code:
  EXPORT BS()  BEGIN   LOCAL UTPLST:={};   LOCAL OKC,UTP;   LOCAL TTL:={"//"};   LOCAL LBL:={"Select"};   LOCAL HLP:="HH";   LOCAL ASTEROIDS:={"ONE","TWO","THREE"};   OKC:=INPUT({{UTPLST,ASTEROIDS}},TTL,LBL,HLP,1,1);   MSGBOX(UTPLST);   OKC:=INPUT({{UTPLST(1),1},{UTPLST(2),1}},TTL,LBL,HLP,1,1);  END; EXPORT UN() BEGIN  BS() END;
(If that code had worked, I would have gone on to replace 1,2 with I=1 to size(ASTEROIDS)...)

Is there a way to do this with a list?

The output could either be a list of the same size as ASTEROIDS, populated with true and false...
Or a smaller list containing just those which have been selected/unselected.

If this cannot be done, could the functionality be added, either to INPUT or CHOOSE?

Stephen Lewkowicz (G1CMZ)
11-10-2015, 05:04 PM (This post was last modified: 11-10-2015 05:17 PM by StephenG1CMZ.)
Post: #2
 StephenG1CMZ Senior Member Posts: 906 Joined: May 2015
RE: Is there a way to input a multi-selection-checkbox of arbitrary length?
I now have a syntax which generates the user interface I was aiming for...
but so far I am entering each list elements manually...
I'm hoping this can be simplified to simply use the whole list
Code:
  EXPORT BS()  BEGIN   LOCAL LST:={};   LOCAL UTPLST:={'LST(1)','LST(2)','LST(3)','LST(4)'};   LOCAL OKC,UTP;   LOCAL TTL:={"//"};   //LOCAL LBL:={"Select"};   LOCAL HLP:="HH";   LOCAL COMETS:={"ALL","Halley","Lewkowicz","The rest"};   //MSGBOX(UTPLST);   OKC:=INPUT({{UTPLST(1),1},{UTPLST(2),1},{UTPLST(3),1},{UTPLST(4),1}},TTL(1)​,COMETS,HLP,1,1);  END; EXPORT UN() BEGIN  BS() END;

Stephen Lewkowicz (G1CMZ)
11-11-2015, 06:42 AM
Post: #3
 cyrille de brébisson Senior Member Posts: 1,047 Joined: Dec 2013
RE: Is there a way to input a multi-selection-checkbox of arbitrary length?
Hello,

So, what you are really looking for is a way to programaticaly create your variable list, both for storing the values AND for the INPUT command...

Why not try:

EXPORT BS()
BEGIN
LOCAL COMETS:={"ALL","Halley","Lewkowicz","The rest"};
LOCAL LST:=MAKELIST(0,I,1,SIZE(COMETS));
LOCAL OKC,UTP;
LOCAL TTL:={"//"};
LOCAL HLP:="HH";
local l2= MAKELIST({'LST(I)',1},I,1,SIZE(COMETS));
OKC:=EVAL(EXPR("INPUT("+STRING(l2)+",TTL(1),COMETS,HLP,1,1)"));
END;

The INPUT command needs both the NAME of the variable and their values...
This is why INPUT does NOT evaluate its first parameter, if it did evaluate it, then it would NOT be able to get the variable name that it needs...
As a result, it is NOT possible to use a programmatic way/method to generate that first parameter, because recalling it, is an evaluation, which does not happen...
Hence the use of a string there to generate the TEXT of the INPUT statement and then the conversion from text to an expression, which is then evaluated...

Cyrille

Although I work for the HP calculator group, the views and opinions I post here are my own. I do not speak for HP.
11-11-2015, 09:09 AM (This post was last modified: 11-11-2015 09:10 AM by StephenG1CMZ.)
Post: #4
 StephenG1CMZ Senior Member Posts: 906 Joined: May 2015
RE: Is there a way to input a multi-selection-checkbox of arbitrary length?
(11-11-2015 06:42 AM)cyrille de brébisson Wrote:  Hello,

So, what you are really looking for is a way to programaticaly create your variable list, both for storing the values AND for the INPUT command...

Why not try:

EXPORT BS()
BEGIN
LOCAL COMETS:={"ALL","Halley","Lewkowicz","The rest"};
LOCAL LST:=MAKELIST(0,I,1,SIZE(COMETS));
LOCAL OKC,UTP;
LOCAL TTL:={"//"};
LOCAL HLP:="HH";
local l2= MAKELIST({'LST(I)',1},I,1,SIZE(COMETS));
OKC:=EVAL(EXPR("INPUT("+STRING(l2)+",TTL(1),COMETS,HLP,1,1)"));
END;

The INPUT command needs both the NAME of the variable and their values...
This is why INPUT does NOT evaluate its first parameter, if it did evaluate it, then it would NOT be able to get the variable name that it needs...
As a result, it is NOT possible to use a programmatic way/method to generate that first parameter, because recalling it, is an evaluation, which does not happen...
Hence the use of a string there to generate the TEXT of the INPUT statement and then the conversion from text to an expression, which is then evaluated...

Cyrille
That looks right, but there is something wrong with the MAKELIST...
It generates LST1...LST1... for some reason.
If that is manually changed to LST1...LST2... Then LST has the desired output.
Code:
EXPORT BS() BEGIN LOCAL COMETS:={"ALL","Halley","Lewkowicz","The rest"}; LOCAL LST:=MAKELIST(0,I,1,SIZE(COMETS)); LOCAL OKC,UTP; LOCAL TTL:={"//"}; LOCAL HLP:="HH"; local l2= MAKELIST({'LST(I)',1},I,1,SIZE(COMETS));  local l2={{'LST(1)',1},{'LST(2)',1},{'LST(3)',1},{'LST(4)',1}}; OKC:=EVAL(EXPR("INPUT("+STRING(l2)+",TTL(1),COMETS,HLP,1,1)"));  MSGBOX(LST); END;

Stephen Lewkowicz (G1CMZ)
11-11-2015, 07:02 PM
Post: #5
 StephenG1CMZ Senior Member Posts: 906 Joined: May 2015
RE: Is there a way to input a multi-selection-checkbox of arbitrary length?
I don't understand why that 2nd MAKELIST didn't generate LST(1...LST(2

But since the INPUT turns list l2 into a string, that MAKELIST isn't needed: one can make the required string directly.

This code seems to achieve what I was looking for:

Code:
  EXPORT BS()  BEGIN   LOCAL ST:="{";   LOCAL COMETS:={"ALL","Halley","Lewkowicz","lots more"};   LOCAL LST:=MAKELIST(0,I,1,SIZE(COMETS));//MAKE LIST FOR RESULTS   LOCAL OKC;   LOCAL TTL:="Select Some";   LOCAL HLP:="HH";   //MAKE STRING FOR INPUT   FOR I FROM 1 TO SIZE(COMETS) DO    ST:=ST+"{LST("+I+"),1}";   END;   ST:=REPLACE(ST,"}{","},{");//COMMA SEPERATOR   ST:=ST+"}";    //MSGBOX(ST);   OKC:=EVAL(EXPR("INPUT("+ST+",TTL,COMETS,HLP,1,1)"));   IF OKC THEN    MSGBOX(LST);   ELSE    //INPUT CANCELLED    //MAY WANT TO EMPTY LST?   END; END;
Many thanks for your help with the syntax.

Stephen Lewkowicz (G1CMZ)
11-12-2015, 06:57 AM
Post: #6
 cyrille de brébisson Senior Member Posts: 1,047 Joined: Dec 2013
RE: Is there a way to input a multi-selection-checkbox of arbitrary length?
Hello,

Yes, indeed the 2nd MAKELIST does do something strange...

But yes, the workaround is, as you stated to make the string directly...

Cyrille

Although I work for the HP calculator group, the views and opinions I post here are my own. I do not speak for HP.
08-23-2018, 09:58 PM (This post was last modified: 08-23-2018 10:24 PM by StephenG1CMZ.)
Post: #7
 StephenG1CMZ Senior Member Posts: 906 Joined: May 2015
RE: Is there a way to input a multi-selection-checkbox of arbitrary length? (SOLVED)
That example code has been re-worked into a callable function here