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: 

operate numericEdit with button interaction and text input

Hi, I'm fairly new to Measurement Studio so bear with me... I change the coercionValue of the NumericEdit control dynamically so if a user goes from nine to ten the coercionValue would change from 1 to 10. The next time the user clicks up on the NumericEdit control the value would be 20, at 100 the next value wuold be 200, and so on. The functionality of this worked fine until I tried entering text. I would input say, 42 while the control's value was at 30 million and the control would respond with 10 million (I'm guessing the smallest number in that order of magnitude). Any suggestions or sample code would be appreciated. Here's what my code currently looks like: private void numTxtStartFreq_AfterChangeValue(object sender, NationalInstruments.UI.AfterChangeNumericValueEventArgs e) { _logged = Math.Log10(numTxtStartFreq.Value); _floored = Math.Floor(_logged); _powered = Math.Pow(10, _floored); if ((!_downPressed || _logged - _floored > 0) && _buttonPressed) { numTxtStartFreq.CoercionInterval = _powered; } _buttonPressed = false; frequencyChange(); } private void numTxtStartFreq_DownButtonClicked(object sender, EventArgs e) { if (_logged - _floored == 0 && numTxtStartFreq.Value > 1 && _buttonPressed) { numTxtStartFreq.CoercionInterval = Math.Pow(10, _floored - 1); } _downPressed = true; _buttonPressed = true; } private void numTxtStartFreq_UpButtonClicked(object sender, EventArgs e) { numTxtStopFreq.CoercionMode = NationalInstruments.UI.NumericCoercionMode.ToInterval; _downPressed = false; _buttonPressed = true; } private void numTxtStartFreq_TextChanged(object sender, EventArgs e) { if (!_buttonPressed) { numTxtStartFreq.CoercionMode = NationalInstruments.UI.NumericCoercionMode.None; numTxtStartFreq.CoercionInterval = 1; _buttonPressed = false; numTxtStartFreq. } } Thanks in advance. Peter
0 Kudos
Message 1 of 4
(3,117 Views)
Sorry The formatting was not correct. 

Hi, I'm fairly new to Measurement Studio so bear with me... I change the coercionValue of the NumericEdit control dynamically so if a user goes from nine to ten the coercionValue would change from 1 to 10. The next time the user clicks up on the NumericEdit control the value would be 20, at 100 the next value wuold be 200, and so on. The functionality of this worked fine until I tried entering text. I would input say, 42 while the control's value was at 30 million and the control would respond with 10 million (I'm guessing the smallest number in that order of magnitude).

Any suggestions or sample code would be appreciated.

Here's what my code currently looks like:

        private void numTxtStartFreq_AfterChangeValue(object sender, NationalInstruments.UI.AfterChangeNumericValueEventArgs e)
        {
            _logged = Math.Log10(numTxtStartFreq.Value);
            _floored = Math.Floor(_logged);
            _powered = Math.Pow(10, _floored);

            if ((!_downPressed || _logged - _floored > 0) && _buttonPressed)
            {
                numTxtStartFreq.CoercionInterval = _powered;
            }
            _buttonPressed = false;
            frequencyChange();
        }

        private void numTxtStartFreq_DownButtonClicked(object sender, EventArgs e)
        {
            if (_logged - _floored == 0 && numTxtStartFreq.Value > 1 && _buttonPressed)
            {
                numTxtStartFreq.CoercionInterval = Math.Pow(10, _floored - 1);
            }
            _downPressed = true;
            _buttonPressed = true;
        }

        private void numTxtStartFreq_UpButtonClicked(object sender, EventArgs e)
        {
            numTxtStopFreq.CoercionMode = NationalInstruments.UI.NumericCoercionMode.ToInterval;
            _downPressed = false;
            _buttonPressed = true;
        }

        private void numTxtStartFreq_TextChanged(object sender, EventArgs e)
        {
            if (!_buttonPressed)
            {
                numTxtStartFreq.CoercionMode = NationalInstruments.UI.NumericCoercionMode.None;
                numTxtStartFreq.CoercionInterval = 1;
                _buttonPressed = false;
            }
        }

 Thanks in advance.

-Peter
0 Kudos
Message 2 of 4
(3,112 Views)
Please could you mention the behavior that you were expecting when entering text 42 into the control. The control will try to coerce the value to the closest value based on the interval without going outside the minimum and maximum value specified by the Range property. If the CoercionInterval is at 20 million when 42 is entered, then according to the behavior mentioned above, the control will set the value to 10 million assuming the range is between 0 (or negative infinity, which is the default value) to some large number (or positive infinity, which is the default value).

The control tries to determine if the value entered is on the coersion interval itself. If so, it does not do anything. Otherwise, it determines if the value is less than or greater than the current value. In either case, it finds the value that is closest to the entered by value by either adding or subtracting the coercion interval from the current value. So, in this case, if the value is 30 million and the CoercionInterval is 20 million, then 42 is less than 30 million, so it subtracts the CoercionInterval from the value to get 10 million. It continues to subtract 20 million from until the value becomes less than the entered value. Accordingly, it then subtracts 20 million from 10 million again to get -10 million. Now, as 10 million is closer to the number 42 than -10 million, it sets the value to 10 million.

I have made assumptions that about the value of the Range and the CoercionInterval which may or may not be correct. If you see a discrepancy from the behavior described above, then please let us.know.

Thanks.
Abhishek Ghuwalewala | Measurement Studio | National Instruments
0 Kudos
Message 3 of 4
(3,097 Views)
Which is why I changed to cercion value in the TextChanged event to 1.  Do I need to do this elsewhere, like in the BeforeChangeValue event? Or is there something else I'm not seeing.

The desired behavior is as follows.  The user can enter in any value as long as it falls within the control perscription i.e. it must be a double within the control's range. But really the user should be able to put in any value they want.  When the user changes the value with buttons, the behavior is as you described, the coercion value changes depending on the control's value property to suit the value's order of magnitude. Both these behaviors are desired.

Thanks,
Peter
0 Kudos
Message 4 of 4
(3,092 Views)