LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Enforcing boundaries for numeric controls

Solved!
Go to solution

Hello!

 

I have a numeric control which has an allowed range between certain values. When a number is entered I need to update a graph. To do this I use EVENT_VAL_CHANGED. The graphic element correctly tells me whether the value entered is within the specified boundaries or not, but this doesn't stop the code in EVENT_VAL_CHANGED from being executed.

 

To solve this temporarily I have made my own function that checks the set boundaries and simply breaks out of the event if the entered number isn't allowed. However, I don't know how to write a generic function that can work with any data type in the numeric control (because I need to provide the correct pointer types when getting the ctrl attributes for the boundaries). 

 

So my questions are the following:

  • Is EVENT_VAL_CHANGED what I want to use in this case, or is another event better to use?
  • Is there any in-built functionality for enforcing the boundaries and not allowing the code to be run if the entered value is "incorrect"?
  • If there isn't: is there a way that I could write my own function that checks the boundaries in a generic way (at least covers both floats and ints).

Disclaimer: I'm very new to CVI, I have basically only read the "Getting Started with LabWindows/CVI" tutorial, and then dived into some old code at work. I'm also "new" to C in that I come from the C++ world.

 

Very thankful for any thoughts on this!

0 Kudos
Message 1 of 4
(1,532 Views)
Solution
Accepted by topic author guybrush_threepwood

What you can do is to set the control in range checking = coerce:

Screenshot 2020-09-04 14.55.31.png

With this option enabled, the control performs a check of the value  and constraints it to the min-max limits range before issuing the commit event. In the example above, if the user inputs 25 and then presses Enter, the value is confined to 20 and then the commit event is fired.

You may need to call SetCtrlAttribute with ATTR_MIN_VALUE and ATTR_MAX_VALUE before displaying the panel if the limits may change at runtime.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 2 of 4
(1,514 Views)
Solution
Accepted by topic author guybrush_threepwood

That is almost exactly what I was looking for! I ended up doing things a little differently, because thanks to your comment I also found the "Control Mode" settings just below the "Range Checking".

 

I kept the range checking as "Notify", set the control mode to "Validate", and moved all my code from EVENT_VAL_CHANGED to EVENT_COMMIT. This allows the user to see the error message if they enter an invalid value, but the code is still only run if a valid value is entered. Of course that only works when the two events are practically interchangable, which they were in my case.

 

Thanks a lot!

0 Kudos
Message 3 of 4
(1,500 Views)

In this case you may use ValidatePanel () command that in a single call tells you whether all controls are in range or not: the typical usage is to call this function when the user wants to save its inputs or dismiss a panel, in order to avoid using or saving incorrect values.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
0 Kudos
Message 4 of 4
(1,481 Views)