I have two Analog Numerics, numerator and denominator, each attached to a tag, num and den. Each has a ValueChanged event defined, which calls a method which divides the two numbers by zero. The tags' values and the result are both pushed to a label. Both the tags have the initial value of 1.
Code: Select all
void numerator_ValueChanged(System.Object sender, Neo.ApplicationFramework.Interfaces.Events.ValueChangedEventArgs e)
{
DivideByZero(Globals.Tags.num.Value, Globals.Tags.den.Value);
}
void denominator_ValueChanged(System.Object sender, Neo.ApplicationFramework.Interfaces.Events.ValueChangedEventArgs e)
{
DivideByZero(Globals.Tags.num.Value, Globals.Tags.den.Value);
}
private void DivideByZero(int num, int den)
{
try
{
int res = num / den;
resultLabel.Text = String.Format("Result: {0} / {1} = {2}", num, den, res);
}
catch(DivideByZeroException)
{
DialogResult dlg = MessageBox.Show( "You divided by zero!",
"Error!",
MessageBoxButtons.OK,
MessageBoxIcon.Hand,
MessageBoxDefaultButton.Button1);
resultLabel.Text = String.Format("Result: {0} / {1} = NaN", num, den);
}
}
I set the denominator to 5, the label is "1 / 1 = 1".
I set the numerator to 10, the label is "1 / 5 = 0".
I set the denominator to 0, the label is "10 / 5 = 2".
I set the denominator to 5, I get a divide by zero popup.
Each event is delayed by one - unless I set the same value in which case the event doesn't fire. This happens during simulation, running and downloading (on a T7B).
Any help is appreciated.