AGG Software
Ask a question  Top  Previous  Next

Script syntax

The program has the built-in scripting engine. The syntax of this script language is compatible with BasicScript or VBScript, but the list of supported functions is fully different. The program folder contains the "ScriptSamples" folder with some examples.

 

Please note, the program will stop all operation for the current block while executing a script. Avoid scripts with a long execution time.

 

The script list of function includes some special functions:

 

function GetValue(Name: string): Varinat

 

This function returns an OPC tag value from any visualization block.

 

Name - the name of the opc tag.

 

function SetValue(Name: string; Value: variant)

 

This function set an OPC tag value in any visualization block.

 

Name - the name of the opc tag.

Value - the new value.

 

function ExecuteFile(FileName, Parameters, WorkingDir: string; Options: integer): integer

 

Executes the specified file.

 

FileName - pass the fully qualified file name

 

Parameters - string that specifies the parameters to be passed to the application

 

WorkingDir - specifies the default (working) directory for the action. If this value is empty, the current working directory is used.

 

Options

 

0 - Hides the window and activates another window.

 

3 - Maximizes the specified window.

6 - Minimizes the specified window and activates the next top-level window in the z-order.

9 - Activates and displays the window. If the window is minimized or maximized, Windows restores it to its original size and position. An application should specify this flag when restoring a minimized window.

5 - Activates the window and displays it in its current size and position.

10 - Sets the show state based on the SW_ flag specified in the STARTUPINFO structure passed to the CreateProcess function by the program that started the application. An application should call ShowWindow with this flag to set the initial show state of its main window.

7 - Displays the window as a minimized window. The active window remains active.

8 - Displays the window in its current state. The active window remains active.

4 - Displays a window in its most recent size and position. The active window remains active.

1 - Activates and displays a window. If the window is minimized or maximized, Windows restores it to its original size and position. An application should specify this flag when displaying the window for the first time.

 

function AppendFile(FileName, Data: string): boolean

 

Appends text to the specified file. If the file does not exists then it will be created.

 

function WriteFile(FileName, Data: string): boolean

 

Writes text to the specified file. If the file already exists then it will be overwritten.

 

function ReadFile(FileName: string): string

 

Reads all text from the specified file.

 

 

GetValue/SetValue demo

 

' Case operator demo

dim val1, val2, name1, name2

 

name1 = "ThisBlockOpcTagName"

name2 = "AnotherBlockOpcTagName"

 

val1 = GetValue(name1)

select case val1

 case 1: val2 = "new value 1"

 case 2..10: val2 = "new value 2"

 case else: val2 = "new value 3"

end select

 

SetValue(name2, val2)

 

File execution demo

 

dim val1, name1

dim working_dir = ""

dim parameters = ""

 

 

name1 = "ThisBlockOpcTagName"

val1 = GetValue(name1)

 

if val1 > 100 then

 ExecuteFile("C:\alert.bat", parameters, working_dir, 0)

end if

 

 

Log file demo

 

dim val1, name1, s

 

name1 = "ThisBlockOpcTagName"

val1 = GetValue(name1)

 

if val1 > 100 then

 s = "Value is too high"

 AppendFile("C:\Logs\log.txt", s) ' create or append to a text file

end if

 




Copyright © 1999-2018, AGG Software.
All rights reserved.