Expression with "if"

A forum devoted to the discussion of all topics having to do with scripting and other advanced programming using iX Developer.
Post Reply
Skeels
Posts: 7
Joined: Thu Jul 25, 2013 4:40 am

Expression with "if"

Post by Skeels »

Hello,
I would like to have do this kind of expression:
if (Globals.Tags.Tag1.Value == 0 && Globals.Tags.Tag2.Value == 0){value = 1;}else{value = 0;}
How can I doing it because it seems not working like that. (I would like maybe use it with more tags in the condition) I would like the value of the tag change without delay obviously.

I tried to use it also in the script file of a tag:
if (Globals.Tags.Tag1.Value == 0 && Globals.Tags.Tag2.Value == 0){return = 1;}else{return = 0;}

Could you indicate what it the best way to do it ?
Thank you,

komppi
Posts: 3
Joined: Tue Sep 03, 2013 11:31 pm

Re: Expression with "if"

Post by komppi »

I had same problem yeasterday!
Solved it like this:
If(condition1)
If(condition2)
{value = 1}
else
{value = 0}

-komppi

Skeels
Posts: 7
Joined: Thu Jul 25, 2013 4:40 am

Re: Expression with "if"

Post by Skeels »

I saw in a topic this kind of operation :

Code: Select all

void Tag1_ValueChange(System.Object sender, Neo.ApplicationFramework.Interfaces.Events.ValueChangedEventArgs e)
{
     if(Globals.Tags.Tag1.Value == 1)
         Globals.Tags.Tag2.Value = 1;
     else
         Globals.Tags.Tag2.Value = 0;
}
But it's not working. Somebody has an idea ?

Thank you

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

Re: Expression with "if"

Post by mark.monroe »

An expression and script code is not the same thing. In expressions you need to set the "value" variable to the result you want iX Dev to use.

This code only works when you are create a script. It will not work in an expression.

Code: Select all

void Tag1_ValueChange(System.Object sender,... 
Best Regards,
Mark Monroe

Beijer Electronics, Inc. | Applications Engineer

Skeels
Posts: 7
Joined: Thu Jul 25, 2013 4:40 am

Re: Expression with "if"

Post by Skeels »

Yes, but I don't what is the best way to do it. expression or script ? And how doing it exactly ?
Thank you for your help,

Skeels
Posts: 7
Joined: Thu Jul 25, 2013 4:40 am

Re: Expression with "if"

Post by Skeels »

I resolved my problem.
If it could help somebody else, I write my code below in Tags' script:

Code: Select all

public partial class Tags
{
void Tag1_ValueChange(System.Object sender, Neo.ApplicationFramework.Interfaces.Events.ValueChangedEventArgs e)
{
if(Globals.Tags.Tag1.Value == 1)
{
Globals.Tags.Tag2.Value = 1;
}
else
{
Globals.Tags.Tag2.Value = 0;
}
}
}

Post Reply