Page 1 of 1

Expression with "if"

Posted: Thu Sep 05, 2013 9:43 am
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,

Re: Expression with "if"

Posted: Thu Sep 05, 2013 11:41 pm
by komppi
I had same problem yeasterday!
Solved it like this:
If(condition1)
If(condition2)
{value = 1}
else
{value = 0}

-komppi

Re: Expression with "if"

Posted: Fri Sep 06, 2013 5:06 am
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

Re: Expression with "if"

Posted: Fri Sep 06, 2013 10:38 am
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,... 

Re: Expression with "if"

Posted: Mon Sep 09, 2013 1:09 am
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,

Re: Expression with "if"

Posted: Mon Sep 09, 2013 3:26 am
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;
}
}
}