2014년 12월 30일 화요일

4 different numbers by a user

Hi all I have a problem.

I have 4 Spinner with numbers in them from 1 to 10

Spinner1 ElementsFromString:1,2,3,4,5,6,7,8,9,10
Spinner2 ElementsFromString:1,2,3,4,5,6,7,8,9,10
Spinner3 ElementsFromString:1,2,3,4,5,6,7,8,9,10
Spinner4 ElementsFromString:1,2,3,4,5,6,7,8,9,10

How do I make sure that the user can not pick the same number 2 time?
Meaning that the user must pick different numbers for each spinner.



Since four is a decent sized number,
it is easier to do this for any arbitrary number
of spinners.

At initialization time, set a list of your spinner
component blocks, called MySpinners.
The component block is the last block in
each spinner's palette.

You will use the Any Spinner blocks to deal
with the spinners in that list.

You will need to build a list of all the numbers
in the range 1 to 10 that have not been
Selected in any of the spinners in list MySpinners.
Call that list UnChosen, and start it at empty().
Use a FOR n in RANGE 1 to 10 loop to test
each n to see if it is worthy of inclusion into the
UnChosen list, using a value procedure you will
write called WasChosen, which accepts a single
number n (1-10) and checks it against each 
spinner Selection value in MySpinners and returns
true if any of them match n.

After you have built up the UnChosen list,
copy it into the Elements list of each spinner
in your MySpinners list.

You will have to repeat this procedure after each
change in the Selection of any spinner.



thank you, but most of what you said was not understood.
any chance of showing examples? 



In Spinner AfterPicking, you have to check and see if the number already was picked or not. This means you have to maintain a list (or equivalent) to maintain picked numbers.



See attachments for how I did it with 5 List Pickers.
I like List Pickers because you can set their text to show their
selection values.  Spinners and List Views can't do that.












I followed the code block by block and got an error.
Error "Property getter was expecting a ListPicker component but got a YailList instead."

plus some of my blocks are different as shown in the pictures in this post...

any help?





I fixed Was_It_Chosen.fw.png
but reset_all_selectors.fw.png is still the same
I still have the error and on run time the ListPickers are empty. 



Here is an alternative, which is maybe simpler. It has 4 spinners. Each spinner is initialized with -,1,2,3,4,5,6,7,8,9,10 (Elements from String)
There is a list of the spinners, which you create when the app starts. For each spinner there must be an .AfterSelection block, which calls a check procedure with as input the spinner number (to be used as index in the found values list and the spinners list. If the selected value is "-", you do nothing. Otherwise you check if the selection is already present. If it is, reset the selection to "-" and show a message. If the value was OK, you check if there are still "-" values in the spinValues list. If they are all goen, you display the chosen numbers in a textbox. Remark that you can still replace numbers by others and the checking will still be ok.




@Ghica - Your is simpler, agreed.

@Nathaniel - Both your screen shots had the same type of error -
You were trying to operate on the entire list instead of
the particular item in the FOR EACH loop that you were up to.

Pay attention to the trailing "s" in the variable names,
which I was using to distinguish between
singular and plural.



Thank you so much I have been at this for days and now it works fully without errors.



thank you.
works well



Glad to help.

Feel free to come by and answer questions or post
tutorials on this group when you feel ready.

For example, your project could be built up into
a tutorial on using lists of Spinners.
There aren't that many tutorials
explaining lists of components out there.


댓글 없음:

댓글 쓰기