Thank you very much, Rohit.
I tried your code also in a CDF. It worked nicely. The code returns the previous entry if the next one falls outside the limits. I rebuilt your code for an upper limit as follows:
`ClearAll[check, val, max]
check[n_] := n <= max
val = 5;
max = 10;
{InputField[Dynamic[val, (If[check[#], val = #, val] &)], Number],
Dynamic[val]}`
Then I tried if it would be possible to get val back to the value of max if this limit is exceeded by replacing the second "val" in the If-statement by "max". So as follows:
ClearAll[check, val, max]
check[n_] := n <= max
val = 5;
max = 10;
{InputField[Dynamic[val, (If[check[#], val = #, max] &)], Number],
Dynamic[val]}`
But this gives the same result as above. So not the value of max. Do you understand why?
A further problem in this context concerns the use of Button to change a value in an inputfield. In its most simple way I like to use the following code for this:
ClearAll[val]
val = 5;
{InputField[Dynamic[val], Number], Button[ "-", val--],
Button["+", val++], Dynamic[val]}
I tried to use this with an If-statement to stay below a given limit in the following way:
ClearAll[check, val, max]
check[n_] := n <= max
val = 5;
max = 10;
{InputField[Dynamic[val], Number], Button[ "-", val--],
Dynamic[Button["+", If[check[#], val = val + 1, val] &]],
Dynamic[val]}
But here the + button no longer works.at all.
Do you have any suggestion?
Thanks in advance, Laurens