Inc/Dec Tag + Validation

A forum devoted to the discussion of all topics having to do with scripting and other advanced programming using iX Developer.
Post Reply
drdeason
Posts: 21
Joined: Wed Jun 26, 2013 6:06 am

Inc/Dec Tag + Validation

Post 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

drdeason
Posts: 21
Joined: Wed Jun 26, 2013 6:06 am

Re: Inc/Dec Tag + Validation

Post 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;
}
}


}

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

Re: Inc/Dec Tag + Validation

Post 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.
Best Regards,
Mark Monroe

Beijer Electronics, Inc. | Applications Engineer

drdeason
Posts: 21
Joined: Wed Jun 26, 2013 6:06 am

Re: Inc/Dec Tag + Validation

Post 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.

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

Re: Inc/Dec Tag + Validation

Post 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;
			}
		}
    }
Best Regards,
Mark Monroe

Beijer Electronics, Inc. | Applications Engineer

drdeason
Posts: 21
Joined: Wed Jun 26, 2013 6:06 am

Re: Inc/Dec Tag + Validation

Post 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.

Post Reply