LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to prevent an enum control from wraping around

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

0 Kudos
Message 1 of 24
(4,333 Views)

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.

0 Kudos
Message 2 of 24
(4,327 Views)

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

 

0 Kudos
Message 3 of 24
(4,287 Views)
Your second point is a good reason. All you have to do is compare the oldval and newval values in the event data. Look for the case where one of them is equal to the minimum enum value and the other is equal to the max enum value. That's your rollover point.

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 4 of 24
(4,264 Views)

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

0 Kudos
Message 5 of 24
(4,236 Views)

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)

Message 6 of 24
(4,201 Views)

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

0 Kudos
Message 7 of 24
(4,168 Views)

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.

0 Kudos
Message 8 of 24
(4,159 Views)
The thing is to decide which behavior is needed, and if the decision is to not rollover, the users' desires are immaterial. The control doesn't rollover.

In terms of an enum with only two values, the whole question goes away since the two behaviors would really be the same because there are only two values.

Finally, I really like the idea of having a configuration setting to prevent rollover. Have you put it on the idea exchange?

Mike...

Certified Professional Instructor
Certified LabVIEW Architect
LabVIEW Champion

"... after all, He's not a tame lion..."

For help with grief and grieving.
0 Kudos
Message 9 of 24
(4,149 Views)

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

0 Kudos
Message 10 of 24
(4,126 Views)