Page 1 of 1

Inc/Dec Tag + Validation

Posted: Fri Aug 09, 2013 11:28 am
by drdeason
I am new to scripting, and I'm not sure where to start. I need the following:

Button1_Click increments the value of a Tag1 by 1, if the value of Tag1 <= 30

Button2_Click decrements the value of a Tag1 by , if the value of Tag1 >= 1

Re: Inc/Dec Tag + Validation

Posted: Fri Aug 09, 2013 12:41 pm
by drdeason
This is what I have so far, but I get this error for the if statement:
"; expected"
or if I add a semi-colon I get this:
"The name 'Tag1' does not exist in current context"

public partial class Screen1
{

void Button1_Click(System.Object sender, System.EventArgs e)
{
If (Tag1.Value < 30)
{
Tag1.Value = Tag1.Value + 1;
}
If (Tag1.Value = 30)
{
Tag1.Value = 1;
}
}


}

Re: Inc/Dec Tag + Validation

Posted: Fri Aug 09, 2013 12:45 pm
by mark.monroe
Try this:
Globals.Tags.Tag1.Value == 30

You refer to tags like this:
Globals.Tags.Tag1.Value

"==" means compare, and "=" means test.

Re: Inc/Dec Tag + Validation

Posted: Fri Aug 09, 2013 12:57 pm
by drdeason
I still get error codes when I rebuild. Either "; expected" without a semicolon after the if statement, or "The name 'If' does not exist in the current context" with a semicolon.

Re: Inc/Dec Tag + Validation

Posted: Fri Aug 09, 2013 1:05 pm
by mark.monroe

Code: Select all

    public partial class Screen1
    {
		
		void Button1_Click(System.Object sender, System.EventArgs e)
		{
			if(Globals.Tags.Tag1.Value < 30)
			{
				Globals.Tags.Tag1.Value += 1;
			}
			if(Globals.Tags.Tag1.Value == 30)
			{
				Globals.Tags.Tag1.Value = 1;
			}
		}
    }

Re: Inc/Dec Tag + Validation

Posted: Fri Aug 09, 2013 1:52 pm
by drdeason
Using an upper case I in the if statement (i.e. If instead of if) was causing the problem. Thanks for the help.