09-04-2020 06:56 AM
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:
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!
Solved! Go to Solution.
09-04-2020 08:02 AM
What you can do is to set the control in range checking = coerce:
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.
09-04-2020 09:02 AM
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!
09-04-2020 10:34 AM
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.