Re: Mathematica: How to force manipulate to accept only discrete values from user?




"Jon McLoone" <jonm@xxxxxxxxxxxxx> wrote in message
news:5db375d0-4aca-46ae-822d-74c648d4600e@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

On Dec 24, 12:59 pm, "Nasser Abbasi" <n...@xxxxxxxxx> wrote:
hello

I am trying to write a manipulate which will accept only integer values.
Sounds easy, right?

Manipulate[Text[c], {{c, -5, "c="}, -10, 10, 1, Appearance -> "Labeled"}]

Now, if I move the slider above, the value do change in discrete amount by
'1' each time, as advertised in the documentation. So 'c' in the above
will
be an integer from -10 to 10.

But the problem is that the user can click on the little '+' at the end of
the slider and open it, and type in any value they want into the text
field
and hit return, and send a 'c' value which is not an integer.

This is a problem, because now I need to check for non-integer values all
the time when I am expecting only integers.

I was wondering if there is a way to make it such that the user can only
enter integer values using the above.
(I do not want to change the manipulate interface to other form).

thanks,
Nasser

I am not sure if you consider this changing the interface, but you could
prevent the InputField from appearing...
Manipulate[Text[c], {{c, -5, "c="}, Slider[#1, {-10, 10, 1}] &}]

Yes, but this option will prevent the label from showing on the right side
of the slider. The label is very useful, as it tells one the actual value of
the variable that the slider is at. By removing it, the user does not know
what is the value of the variable when they move the slider around.

(btw, one can write Manipulate[Text[c], {{c, -5, "c="}, -10, 10, 1,
Appearance -> "Closed"}] for the same effect as your example).

Does any one know of a way to have the Appearance be closed, but also
display the variable value as the slides moves? I looked at Slider[]. I
might have to use Dynamic[] to get it to work, but not sure now. If I can
get a the label to show up, and at the same time prevent the user from
typing something in the text field, this would be ok solution.


InputField lets you type a new value for a variable but does not have
a filtering mechanism before committing. So you need to do that within
the evaluation. Either...

Manipulate[If[TestForAccapetableChangedValue[c2,c],c2=c];Text[c2],
{{c, -5, "c="}, -10, 10, 1, Appearance -> "Labeled"}]
Or, I think better, change the value to something acceptable, which
will also automatically change the contents of the input field. In
this case...
Manipulate[c=Round[c];Text[c], {{c, -5, "c="}, -10, 10, 1, Appearance -
"Labeled"}]

The above is what I ended up doing (I had to round down/up depending on
other things). But this solution is not good either for the following
reason: A user enters say 2.3 (when they know that the program only wants an
integer, but I have no way to force this using a Text field). Now the
program will round the value, and process '2' internally (by rounding it)
and return a result for '2'. Which is misleading to the user. The user
might think that '2.3' was used even though the content of the input field
would have changed to '2'.

Another solution is to check if the value entered is not an integer, and
complain to the user with maybe a pop-up error message, and force the user
correct their input.

Thanks for your response.

Nasser


.



Relevant Pages

  • Re: Mathematica: How to force manipulate to accept only discrete values from user?
    ... I am trying to write a manipulate which will accept only integer values. ... Now, if I move the slider above, the value do change in discrete amount by ... (I do not want to change the manipulate interface to other form). ... InputField lets you type a new value for a variable but does not have ...
    (sci.math.symbolic)
  • Re: [Mathematica] Manipulate[] update question
    ... I have this 3 lines manipulate, where I expect the display to update as ... I move the slider. ... let me explain how I understand Manipulate: ... I found that if I have the control variable itself in the expression, then the expression will re-evaluate. ...
    (sci.math.symbolic)
  • Mathematica: How to force manipulate to accept only discrete values from user?
    ... I am trying to write a manipulate which will accept only integer values. ... Now, if I move the slider above, the value do change in discrete amount by ... the time when I am expecting only integers. ... (I do not want to change the manipulate interface to other form). ...
    (sci.math.symbolic)
  • Re: Mathematica: How to force manipulate to accept only discrete values from user?
    ... I am trying to write a manipulate which will accept only integer values. ... Now, if I move the slider above, the value do change in discrete amount by ... The Manipulator label is actually an inline input field, ... have to use a different control or add a custom control function: ...
    (sci.math.symbolic)
  • Re: Slider Bar for Survey
    ... there are third party controls for this e.g. Microsoft Slider ... Control that you may have installed on your system. ... Place a label over the line (background ... Private Sub lblBackground_MouseDown(Button As Integer, Shift As Integer, X ...
    (microsoft.public.access.forms)