16.3 VB Script

In this section, you can find the method of writing a script using functions and subroutines[1]. When you write a script, please be aware of the following precautions.

  • When you use a function in the script, there must be brackets since it has a return value. Brackets should be removed in subroutines.

  • When you use functions and subroutines in command expression, they must be used with brackets.

  • In the script, the functions and subroutines have to be differentiated.

  • Please refer to the appendices of ‘Script’ and ‘Operation and Command Expressions’ manual.

 

(1)     Writing a Script

a)         In the database editor, create an analog tag named ‘VALUE’.

 

b)        Select [Tools] – [Script] or  icon to bring up the script editor. Press  icon to create a new script.

 

c)      Write a script as shown below. This script changes the value of the ‘VALUE’ tag.

 

d)      When the script is called, it executes the functions and ends automatically. If you use ‘While’ statement as used in c), the script will loop infinitely. In this case, you can stop the script using StopScript() function.

  • ‘Sleep’ function must be included in the While statement to pause the operation at least 100msec. Otherwise, the script will loop continuously, which will cause the latency in the project operation.

 

e)      Press [!] button in the editor to compile the script.

f)      Select [File] – [Save] or  icon to save the script to the project.

g)     Select [Draw] – [Tag Value] or  icon to add the tag value object to the graphic page, which will display the value of the ‘VALUE’ tag.

 

(2)    Script Run / Stop

a)      You can run or stop the script with the following subroutines.

  • Subroutine for the script execution

Subroutine

Command

RunScript(“Script Name”)

Script

RunScript “Script Name”

Description

Executes the assigned script.

Example

Runs the script named ‘ValueChange’.

RunScript(“ValueChange”)

 

Subroutine

Command

RunScriptEx(“Script Name”, Option, Parameter)

Script

RunScriptEx “Script Name”, Option, Parameter

Description

Executes the assigned script according to the option and parameter.

Option

0

No action is taken if the assigned script is currently running.

1

Waits until the script stops and runs the script with Parameter.

Parameter

A parameter conveyed to the script. The script can receive the parameter using GetParameter() function.

Example

Convey the parameter ‘Test’ to the script and executes the script named ‘ValueChange’.

RunScriptEx(“ValueChange”, 1, Test)

  • Subroutine to stop the script

Subroutine

Command

StopScript(“ValueChange”)

Script

StopScript “ValueChange

Description

Stops the assigned script.

Example

Stops the script named ‘ValueChange’.

StopScript(“ValueChange”)