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
Inc/Dec Tag + Validation
Re: Inc/Dec Tag + Validation
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;
}
}
}
"; 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;
}
}
}
-
- Posts: 824
- Joined: Tue Mar 13, 2012 9:53 am
Re: Inc/Dec Tag + Validation
Try this:
Globals.Tags.Tag1.Value == 30
You refer to tags like this:
Globals.Tags.Tag1.Value
"==" means compare, and "=" means test.
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
Mark Monroe
Beijer Electronics, Inc. | Applications Engineer
Re: Inc/Dec Tag + Validation
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.
-
- Posts: 824
- Joined: Tue Mar 13, 2012 9:53 am
Re: Inc/Dec Tag + Validation
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
Mark Monroe
Beijer Electronics, Inc. | Applications Engineer
Re: Inc/Dec Tag + Validation
Using an upper case I in the if statement (i.e. If instead of if) was causing the problem. Thanks for the help.