Combination "ValueChange" in Tag Script

A forum devoted to the discussion of all topics having to do with scripting and other advanced programming using iX Developer.
Post Reply
Joe
Posts: 27
Joined: Tue Sep 18, 2012 4:53 am

Combination "ValueChange" in Tag Script

Post by Joe »

Hi,
how can I combine following conditions, for better transparency :?:

----------------------------------
void Station2_M700_ValueChange(System.Object sender, Neo.ApplicationFramework.Interfaces.Events.ValueChangedEventArgs e)
{
ScriptModule1.Start();
}

void Station2_M710_ValueChange(System.Object sender, Neo.ApplicationFramework.Interfaces.Events.ValueChangedEventArgs e)
{
ScriptModule1.Start();
}
----------------------------------
Like this ... ? ->

"Station2_M700_ValueChange or Station2_M710_ValueChange"
{
ScriptModule1.Start();
}
----------------------------------
Thanks for reply

Joe

mark.monroe
Posts: 824
Joined: Tue Mar 13, 2012 9:53 am

Re: Combination "ValueChange" in Tag Script

Post by mark.monroe »

Create a function that calls ScriptModule1.Start(). Then use that function in both of your ValueChange events.

You are free to create your own functions in a screen script. You do not have to use ours.

Code: Select all

namespace Neo.ApplicationFramework.Generated
{
    using System.Windows.Forms;
    using System;
    using System.Drawing;
    using Neo.ApplicationFramework.Tools;
    using Neo.ApplicationFramework.Common.Graphics.Logic;
    using Neo.ApplicationFramework.Controls;
    using Neo.ApplicationFramework.Interfaces;
    
    
    public partial class Screen1
    {
		
		void Button1_Click(System.Object sender, System.EventArgs e)
		{
                       MyFunction();
		}
		
		void MyFunction()
		{
			ScriptModule1.Start();
		}
		
    }
}
Best Regards,
Mark Monroe

Beijer Electronics, Inc. | Applications Engineer

Patrick Hall
Posts: 22
Joined: Fri May 25, 2012 7:44 am
Location: Charlotte, NC. USA

Re: Combination "ValueChange" in Tag Script

Post by Patrick Hall »

A slightly different option is the one I use. I create 1 single ValueChanged event, or manually create a function with matching signature. Per your existing convention.

Code: Select all

void Station2_Mxxx_ValueChange(System.Object sender, Neo.ApplicationFramework.Interfaces.Events.ValueChangedEventArgs e)
{
    ScriptModule1.Start(); 
}
Now from the script editor for Tags you can right click each tag you wish to use this ValueChange event code, and "Hookup existing..."
Hookup Event Handler
Hookup Event Handler
Hookup ValueChange Evt Hndler.png (29.74 KiB) Viewed 8844 times
You can also cast "sender" to a GlobalDataItem if you want to gain access to the Tag's name, Gain, or Value for further specific function upon the change in value.

For Example, Assuming 4 Tags [Tag1 ... Tag4] are created, each assigned the same event handler.

Code: Select all

void Station2_Mxxx_ValueChange(System.Object sender, Neo.ApplicationFramework.Interfaces.Events.ValueChangedEventArgs e)
{
    GlobalDataItem tag = (GlobalDataItem)sender;
    if(tag.Name.Equals("Tag2"))
        MessageBox.Show("Tag2 Was Changed!");
}
You can now react to an individual condition (such as Name) depending on which tag was changed.

This is the methodology I use to create a central value change event handler and dispatch functionality to other Class Methods depending on the desired behavior I want.
Best Regards,
Patrick Hall

Post Reply