02-12-2015 10:06 AM
Hello,
I created an enum control and find that when I click the down button over and over again the value will wrap around and begin again at the first entry in the enum list.
How can I prevent this? I want it to stop, when it reached the last enum list entry. And of course the same upwards.
Thanks a lot
Martin
02-12-2015 10:14 AM
There are a couple of workarounds you could do with event structures, but the real question is: why is this a problem for you? Perhaps an enum is not the best option.
02-13-2015 04:53 AM
Hello,
> Why is that a problem for me?
There are a number of answers:
- User experience or intuitive handling: clicking down means to reduce the value or just one step down the list. If you are suddenly at the highest value or top of the list it may be confusing. Maybe that is just my feeling
- in my application changing the value takes effect immedeately with small steps in the effect from one value to the next - except at the wrap around
- programmers habit - I have not seen such a behaviour in other programming tools, I was really surprised, also that it can not be switched off.
I 'll be glad to read about other possibilities to solve this task.
Thanks a lot
Martin
02-13-2015 07:04 PM
02-14-2015 02:44 PM
I guess I made Lemonade from this Lemon. I wanted to iterate through all the values of the enum, without worrying about which was first or last. This turned out to be very simple -- I created a While loop, brought the variable of the enum's type into a shift register, and also into a tunnel. Within the loop, I did whatever I needed to do with the variable on the Shift Register, incremented the Shift Register, and compared the value with the initial value on the tunnel, wiring this to the Stop condition. Now no matter what value is on my Variable, this loop will "loop through" all of the Enum values, starting with the value I wire in.
If you want to constrain the values on the Front Panel when you increment and decrement, create a Value Changed for the Front Panel object and test New Val -- if it is equal to Top or Bottom, put Old Val back on top of it (my inclination would be to use a Value Property of the Control, rather than wiring to a Local Variable). [Others have also suggested this here ...]
Bob Schor
02-16-2015 02:58 AM
We wanted to do something similar but unfortunately, the solutions provided here don't work properly.
You can't simply discard a user change if the old value was at the max and the new value is at the minimum because what if that's what the user really wants to do? If the software doesn't allow this, but will allow a change from maximum to second minimum then this will feel like a real bug to the user. And rightly so.
Also, what on earth do you do when your enum only had two entries? Once you choose one value you can never change it again......
We investigated several options and couldn't find a suitable solution which also works when the user clicks and holds on the increment or decrement button. The "Value Changed" events come thick and fast and even changing key focus and other options have no effect on this scenario once the click-and.hold train has left the station.
Personally I would like if an enum control whose input settings are "Coerce to range" would NOT wrap at all. I have yet to find a proper method to prevent the control wrapping if the user simply clicks and holds (apart from completely disallowing the click and hold functionality which is possible)
02-16-2015 10:02 AM
I was about to argue with you, then tried to program the "obvious" solution, and found that (no surprise to you, I'm sure) you are basically right -- it is a trickier problem than it first appears.
BS
02-16-2015 10:44 AM - edited 02-16-2015 10:45 AM
I really wish you would have argued with me because this would mean you maybe found a way to do what I couldn't.....
But as it is, yeah I've been there, tried that, tried several variations and then gave up.
02-16-2015 10:54 AM
02-16-2015 12:05 PM
I loooked at this a little also and could not find a good solution.
Using separate latch-action booleans for increment and decrement along with an event structure writing to a local variable of the enum comes close. Another compiication arises if one (or more) of the end items are disabled. The local variable can set the enum to one of the disabled states. So extra logic is required to check the disabled items.
I did not pursue it far enough to get something which appeared to meet the OP's requirements.
The idea exchange seems like the best route.
Lynn