1. Getting user's input from a menu of choices
I asked recently, how to code for the situation where the user is presented
with a menu consisting of several non mutually exclusive choices... eg MENU
OF CHOICES
A this
B that
C other
...or 1 this
2 that
3 other
...and is prompted to enter them (eg A C; or 1 2 3 )
I now realise my question is more about this:
1 if I try to use choice = get(0) to get the input, I have to know
beforehand how many choices there'll be, to issue get() the right number of
times. Must I ask the user to specify beforehand the number of choices, or
else use a sentinel value?
2 if I use choice = gets(0), I get a sequence of ASCII values. Eg if the
user's input was... 1 3 2
gets(0) would return {49,51,50,10}
After removing choice[4], I don't know how to re-create {1,3,2}
I'm particularly interested in ending up with a sequence of numbers,
because I want to use them as indices for elements of other sequences Eg:
sequence all_choices, choice
all_choices = { "up", "down", "right", "left", "stop" }
for i = 1 to length(choice) do -- where choice = {1,3,2}
index = choice[1]
puts(1, all_choices[index])
end for
Thanks in advance for any newbie-level solutions.
Alex Caracatsanis
2. Re: Getting user's input from a menu of choices
On Sun, 13 Aug 2000, Alex wrote:
<snip>
> I'm particularly interested in ending up with a sequence of numbers,
> because I want to use them as indices for elements of other sequences Eg:
> sequence all_choices, choice
>
> all_choices = { "up", "down", "right", "left", "stop" }
>
> for i = 1 to length(choice) do -- where choice = {1,3,2}
> index = choice[1]
> puts(1, all_choices[index])
> end for
>
> Thanks in advance for any newbie-level solutions.
>
> Alex Caracatsanis
Hi Alex:
This will do what you want:
include graphics.e -- for color names
include dialogs.e -- dialogs
constant choices = {"This","That","TheOther"}
object result
position(10,20) -- position the box
SetSize(10,50) -- size of box
result = CheckBox("Please select one or more",choices)
for i = 1 to length(result) do
result[i]= find(result[i],choices)
end for
? result
-- result returns a sequence, {} = no choices,
-- {1,3} if choices were"This" and "TheOther", etc.
Regards,
Irv