From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

Measurement Studio for .NET Languages

cancel
Showing results for 
Search instead for 
Did you mean: 

Handling out of range exceptions thrown by Numeric Edit

Hi,
 
I am using NI Numeric Edit Boxes on a form to restrict user input to numeric values within a certain range.  I have set the "OutOfRangeMode" property for each of the boxes  to "Throw Exception" (as this is more appropriate for my application), but how do I detect / handle this exception programmatically (Visual Basic.Net) without a Try/Catch statement????  At the moment, an "unhandled exception" message is displayed when the input to the edit box is out of range or negative (see below) and I would like to have a custom message box (depending on the edit box in question) and set the value of the edit box to a specific number when an exception is thrown.
 
Thanks to anyone who can help.
 
************** Exception Text **************
System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
Parameter name: value
   at NationalInstruments.Restricted.NumericControl.a(Double , Action , Boolean )
   at NationalInstruments.Restricted.NumericControl.SetValue(Double value, Action action)
   at NationalInstruments.UI.WindowsForms.NumericEdit.a(Double , Action )
   at NationalInstruments.UI.WindowsForms.NumericEdit.a(String , Boolean , Action )
   at NationalInstruments.UI.WindowsForms.NumericEdit.OnLeave(EventArgs e)
   at System.Windows.Forms.Control.NotifyLeave()
   at System.Windows.Forms.ContainerControl.UpdateFocusedControl()
0 Kudos
Message 1 of 3
(3,155 Views)
why do you want to avoid try/catch ?
Philip Newman
General Dynamics
Electric Boat
0 Kudos
Message 2 of 3
(3,148 Views)
You can detect this condition by adding an event handler for the BeforeChangeValue event of the NumericEdit control. In the event handler:

            if (!numericEdit1.Range.Contains(e.NewValue))
            {
                // Exception will be thrown

                e.Cancel = true;
            }
            else
            {
                // Exception will NOT be thrown
            }

The above example assumes that a NumericEdit instance called numericEdit1 has been declared and initialized.

Abhishek Ghuwalewala | Measurement Studio | National Instruments
0 Kudos
Message 3 of 3
(3,138 Views)