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
|