Delayed events

Discussion of application development using iX Developer, including but not limited to getting started, using the functions tab, properties, objects and installation.
Post Reply
sjdebdaly
Posts: 2
Joined: Fri Nov 22, 2013 6:45 am

Delayed events

Post by sjdebdaly »

Hi all, I seem to have come up with a case of events being delayed.

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);
	}
}
What's going wrong:

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.

sjdebdaly
Posts: 2
Joined: Fri Nov 22, 2013 6:45 am

Re: Delayed events

Post by sjdebdaly »

I fixed this problem last week. The fault was that I was using the ValueChanged event and then using the tags attached to the object owning the event instead of using the variable supplied in the event arguments. The tags get updated after the event has fired, giving the illusion that it is one event behind.

Post Reply