Press "Enter" to skip to content

Script – Basic expressions

Basic expressions:

1 – IF
2 –  For
3 – While
4 – Goto

(To understand how to introduce the script in the SCADA software:  Script – Introduction – Step 1)

1 – IF

If expression indicates a decision based on condition.

If <expression> Then

End If

Example 1 (Tag1 as numeric tag and message1 as text tag):

If ( Tag1 = 2 ) Then
 message1 =  “Alarm 2”
End If

Example 2 (Tag1 as numeric tag and response as text tag):

If  Not ( response = “ERROR” ) Then
 Tag1 =  3
End If

Example3 (Else and ElseIf expression)

If ( Tag1 = 1 ) Then
 Tag2 = 1
 Tag3 = 3
 Tag4 = 7
ElseIf ( Tag1 = 2 ) Then
 Tag2 = 7
 Tag3 = 1
 Tag4 = 3
Else
 Tag2 = 1
 Tag3 = 7
 Tag4 = 1
End If

Important: expression ElseIf demands an Else at the final, even if it is empty.

2 – For

For command makes a loop variable go from one value to another.

For <variable> = <inicial> to <final>
 …
Next

Example:

For i = 1 to 10
  tag(“Tag”+CStr(i)) = i
Next

Important: This expression should only be used for quick operations. In slow cases, instead of For, a loop must be made by a global variable adding to each OnGroup or OnAfterUpdate execution.

3 – While

Expression While performs a loop while a condition is true

While <condition>
 …
WEnd

Example:

i = 1
While i <= 10

  tag(“Tag”+CStr(i)) = i
  i = i + 1
Next

Important: This expression should only be used for quick operations. In slow cases, instead of While, a loop must be made by a global variable adding to each OnGroup or OnAfterUpdate execution.

 

4 – GoTo

Command GoTo leads the execution of the script to a label position.

 

Goto labelname

….

labelname:

 

 

Question?