IUAVariable.VariableChange
This event occurs when the value of the project variable that the
IUAVariable
C# object references changes.event EventHandler<VariableChangeEventArgs> VariableChange;
IMPORTANT:
If the project variable refers to a field variable, the event is generated only if the project variable is kept synchronized with the field through a
RemoteVariableSynchronizer
object, unless a link to the following entities already exists in FactoryTalk Optix Studio
:
- Tag variable from a graphical object
- Data logger object
- Alarm
- Recipe schema object
In such a scenario, in a NetLogic, you can subscribe the change value method directly to the linked tag variable.
Event handler
The
VariableChange
event handler enables you to subscribe a method to the event of the same name.
public delegate void VariableChange(object sender, VariableChangeEventArgs e);
Event handler arguments
- sender(object)
- A C# object that corresponds to the object of the project origin of the event.
- e(VariableChangeEventArgs)
- A C# object that contains the following properties:
- variable(IUAVariable)
- The project variable that generated the event.
- newValue(UAValue)
- The new value of the variable.
- oldValue(UAValue)
- The previous value of the variable.
- indexes(uint[])
- Only for arrays:The indexes of the array cells in which the value has changed.TIP: The property is empty if the value in each cell changes or if the project variable is scalar.
Example
The
Variable1_VariableChange
method is executed each time the project variable Variable1
changes value.
public override void Start() { var variable1 = Project.Current.GetVariable("Model/Variable1"); variable1.VariableChange += Variable1_VariableChange; } private void Variable1_VariableChange(object sender, VariableChangeEventArgs e) { var label1 = Owner.Get<Label>("Label1"); label1.Text = "Value of " + e.Variable.BrowseName + " changed from " + e.OldValue + " to " + e.NewValue; }
Provide Feedback