Post Reply 
Multiple Choice for CHOOSE command
08-09-2018, 07:07 AM
Post: #1
Multiple Choice for CHOOSE command
Hello,
I was wondering if there was the possibility to choose multiple items through the CHOOSE interface but this command just give the possibility to choose one item...

Then I decided to nest the choose command into a repeat...until loop in order to show the choose interface again and again modifying the element chosen by the user from ‘element nth’ to ‘* element nth’ to show the list of item already selected.

For example if the program asks for ‘ice cream preferred flavors’ the user could select multiple flavors like ‘vanilla’, ‘strawberry’ and ‘coffee’.

This system (CHOOSE command nested into a REPEAT...UNTIL loop) work until you don’t have to exit from the loop. Which condition? I don’t know how to exit from the test because there is no way to understand when the user stops the selection of items...

What do you suggest here?

The only solution I see is to ask the development team to provide the CHOOSE command with multiple selection (yes the variable would be a list at this point) and a menu selection (CANCEL....OK) to complete or cancel the execution of this command.

And since I am here asking to modify some code ;-) I’d like to ask to enlarge the space given to the CHOOSE command graphical interface in order to fill the whole screen and not just a small window. The current size of the interface limit the size of the strings to show.

Thanks

Giancarlo
Find all posts by this user
Quote this message in a reply
08-09-2018, 08:13 AM (This post was last modified: 08-09-2018 08:42 AM by Carlos295pz.)
Post: #2
RE: Multiple Choice for CHOOSE command
(08-09-2018 07:07 AM)Giancarlo Wrote:  For example if the program asks for ‘ice cream preferred flavors’ the user could select multiple flavors like ‘vanilla’, ‘strawberry’ and ‘coffee’.

This system (CHOOSE command nested into a REPEAT...UNTIL loop) work until you don’t have to exit from the loop. Which condition? I don’t know how to exit from the test because there is no way to understand when the user stops the selection of items...

It can be achieved like this:
Code:
  LOCAL List={"vanilla","strawberry","coffee","coconut","chocolate"};
  LOCAL X,SList={};
  WHILE CHOOSE(X,"Chosen ("+SIZE(SList)+")",List) DO
    SList:=UNION(SList,X)
  END;
  L1:=List;
  MSGBOX(EXECON("L1(&1)",SList))

[Esc] on CHOOSE return a 0

Viga C | TD | FB
Visit this user's website Find all posts by this user
Quote this message in a reply
08-09-2018, 08:35 AM (This post was last modified: 08-09-2018 08:46 AM by Carlos295pz.)
Post: #3
RE: Multiple Choice for CHOOSE command
Another more visual alternative

Code:
GENLIST(List,Chosen)
BEGIN
  FOR X:=1 TO SIZE(List) DO
    List(X):=IFTE(POS(Chosen,X),"● ","○ ")+List(X)
  END
END;

EXPORT CHOSEN
BEGIN

  LOCAL List={"vanilla","strawberry","coffee","coconut","chocolate"};
  LOCAL X,SList={};

  WHILE CHOOSE(X,"Chosen ("+SIZE(SList)+")",GENLIST(List,SList)) DO
    SList:=IFTE(POS(SList,X),DIFFERENCE(SList,X),UNION(SList,X))
  END;

  L1:=List;
  MSGBOX(EXECON("L1(&1)",SList))
END;

It is possible to add the exit option without problems

Viga C | TD | FB
Visit this user's website Find all posts by this user
Quote this message in a reply
08-09-2018, 11:14 AM (This post was last modified: 08-09-2018 09:06 PM by StephenG1CMZ.)
Post: #4
RE: Multiple Choice for CHOOSE command
It is possible to select multiple choices from an arbitrary list without repeatedly asking for one choice at a time.
I asked this question a long time ago and Cyrille and I found a solution:
http://www.hpmuseum.org/forum/thread-509...ight=comet

On later compilers, Perhaps an easier syntax is now available?

Stephen Lewkowicz (G1CMZ)
Visit this user's website Find all posts by this user
Quote this message in a reply
08-09-2018, 12:02 PM
Post: #5
RE: Multiple Choice for CHOOSE command
You could use the input() form with a multiple check box selection.
Find all posts by this user
Quote this message in a reply
08-11-2018, 09:19 PM
Post: #6
RE: Multiple Choice for CHOOSE command
Hello,
The solution provided by Carlos works like a charm. Every time the user selects an element, the item is flagged, the counter is updated (in the title) and the result of the choices is stored into a variable (a list).

The user by the way, as you write, exit the choose menu with ESC which is not very intuitive but it works.

Thank you very much. Still have to verify the other solutions provided in this thread. I will try them in the next days,

Thanks

Giancarlo

P.S. not sure i under what you had in mind with the EXECON command. I just put in the message box the SList.
Find all posts by this user
Quote this message in a reply
08-12-2018, 07:36 AM
Post: #7
RE: Multiple Choice for CHOOSE command
Hello Carlos,
Which exit option do you see to close the WHILE...DO loop?

Thanks

Giancarlo

P.S I understood the execon command. You use the position of the chosen item until the end of the code where you use the execon command to replace the position in the list with its string.
Find all posts by this user
Quote this message in a reply
08-12-2018, 07:46 AM (This post was last modified: 08-12-2018 07:47 AM by Carlos295pz.)
Post: #8
RE: Multiple Choice for CHOOSE command
Pressing Esc or pressing the screen outside of the options, that will cause CHOOSE to return 0, meaning that no option was chosen

Viga C | TD | FB
Visit this user's website Find all posts by this user
Quote this message in a reply
08-13-2018, 09:38 AM
Post: #9
RE: Multiple Choice for CHOOSE command
To complete the cases, when it is necessary confirm the change of elections, it can be done as follows:

Final option to save changes

Code:

GENLIST(List,Chosen)
BEGIN
  CONCAT(MAKELIST(IFTE(POS(Chosen,A),"● ","○ "),A,1,SIZE(List))+List,{"➪ Check all","➪ Uncheck all","➪【 Save changes 】 "})
END;

GENCHOOSE(List,SList)
BEGIN
  LOCAL X,Size=SIZE(List),Prev=SList;
  WHILE CHOOSE(X,"Chosen ("+SIZE(SList)+")",GENLIST(List,SList)) DO
    CASE
      IF X≤Size THEN SList:=IFTE(POS(SList,X),DIFFERENCE(SList,X),UNION(SList,X)) END
      IF X=Size+1 THEN SList:=MAKELIST(A,A,1,Size) END
      IF X=Size+2 THEN SList:={} END
        RETURN SORT(SList);
    END
  END;
  Prev
END;

PRINTCHOSEN(List,SList)
BEGIN
  IF SIZE(SList) THEN
    MAKELIST(PRINT("- "+List(SList(A))),A,1,SIZE(SList))
  ELSE
    PRINT("** Empty **")
  END
END;


EXPORT CHOSEN
BEGIN

  LOCAL List,SList;
  PRINT;

  List:={"vanilla","strawberry","coffee","coconut","chocolate"};
  SList:={2,3}; //Initial
  SList:=GENCHOOSE(List,SList); //Final

  PRINT("Chosen 1");
  PRINTCHOSEN(List,SList);

  List:={"Red","Green","Blue","Cyan","Magenta","Yellow","Black","White"};
  SList:={1,4,5}; //Initial
  SList:=GENCHOOSE(List,SList); //Final

  PRINT("-----\nChosen 2");
  PRINTCHOSEN(List,SList)

END;

Ask if changes are saved when leaving if they exist

Code:
GENLIST(List,Chosen)
BEGIN
  CONCAT(MAKELIST(IFTE(POS(Chosen,A),"● ","○ "),A,1,SIZE(List))+List,{"➪ Check all","➪ Uncheck all"})
END;

GENCHOOSE(List,SList)
BEGIN
  LOCAL X,Y,Size=SIZE(List),Prev=SORT(SList);
  WHILE CHOOSE(X,"Chosen ("+SIZE(SList)+")",GENLIST(List,SList)) DO
    CASE
      IF X=Size+1 THEN SList:=MAKELIST(A,A,1,Size) END
      IF X=Size+2 THEN SList:={} END
        SList:=IFTE(POS(SList,X),DIFFERENCE(SList,X),UNION(SList,X))
    END
  END;
  IF NOT EQ(Prev,SORT(SList)) AND CHOOSE(Y,"Save Changes?",{"Yes","No"})=1 THEN
    SORT(SList)
  ELSE
    Prev
  END
END;

PRINTCHOSEN(List,SList)
BEGIN
  IF SIZE(SList) THEN
    MAKELIST(PRINT("- "+List(SList(A))),A,1,SIZE(SList))
  ELSE
    PRINT("** Empty **")
  END
END;


EXPORT CHOSEN
BEGIN

  LOCAL List,SList;
  PRINT;

  List:={"vanilla","strawberry","coffee","coconut","chocolate"};
  SList:={2,3}; //Initial
  SList:=GENCHOOSE(List,SList); //Final

  PRINT("Chosen 1");
  PRINTCHOSEN(List,SList);

  List:={"Red","Green","Blue","Cyan","Magenta","Yellow","Black","White"};
  SList:={1,4,5}; //Initial
  SList:=GENCHOOSE(List,SList); //Final

  PRINT("-----\nChosen 2");
  PRINTCHOSEN(List,SList)

END;

Viga C | TD | FB
Visit this user's website Find all posts by this user
Quote this message in a reply
Yesterday, 02:57 PM
Post: #10
RE: Multiple Choice for CHOOSE command
Hello Carlos,
Just found some time to play with your code. Very compact code!
I like the way you shrink the code.

Adding “check all” and “uncheck all” is very helpful. At this point do you think it is possible to add another item like “end” to close the choose interface to act like the [ESC] command?

Very good job!

Giancarlo
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)