You are on page 1of 437

Using View Scripting Functions

ViewScript syntax | Active Scripting syntax

(This topic applies only to Windows PC and QuickPanel View/Control targets. View scripting
functions by target indicates which functions each target supports. For a list of View functions
supported by QuickPanel targets, see QPScript Functions list.)

View scripting functions perform operations or calculations in a View script.


The process of executing a script function is often termed "calling" the
function. This topic explains the general syntax used to call these functions. A
description of the specific syntax for each function is also included in the topic
devoted to each function.
Most script functions include parameters. These are extra settings that you
pass to the script function that specify the action in greater detail. For
example, the Message script function opens a dialog box with a text
message. The function includes a parameter named strMessageString. When
you call the Message function within a script, you replace strMessageString
with whatever message you want to display.
Some parameters are optional. These parameters, indicated with square
brackets ("[" and "]"), typically let you override default functionality for a
script function. For example, the Message function has an optional parameter
named numChooseButton. By default, the dialog box appears with OK and
Cancel buttons and an "Information" icon; the numChooseButton parameter
lets you change this.

ViewScript script function syntax


Scripts written in ViewScript use the following syntax.
FunctionName parameter1, parameter2, ...

Active Scripting script function syntax


Scripts written in VBScript use the following syntax. Script functions that do
not return a value use:
View.FunctionName parameter1, parameter2, ...
For script functions that return a value use:
View.FunctionName(parameter1, parameter2, ...)
Also, parameters that require names of items or variables in your project
must be included as string parameters. For details, see View script function
parameter naming conventions.
Notes

● When a VBScript Active Scripting function expects a variable, then only local VBScript
variables (defined with a DIM, PRIVATE, or PUBLIC statement) can be used. Variables
from the Machine Edition variable database cannot be used.
● When passing function parameters by reference, ensure that each variable's Mark As Used
property is set to True.
View Scripting Functions

(These functions are only supported by Windows PC and QuickPanel View/Control targets. View
scripting functions by target indicates which functions each target supports. For a list of View
functions supported by QuickPanel targets, see QPScript Functions list.)

View scripting functions are commands that can be used in View scripts.
Scripts often automate processes based on variable values or events.
Script functions are sorted into the following groups:

Function Group Description


ActiveX Allow scripts to interact with ActiveX
controls during runtime.
Alarm Management Allow scripts to interact with alarm
objects.
Animation Execute animation operations using
a script.
Application Access (App Control) Launch other Microsoft Windows
applications and send keystroke
commands to them.
CSV File management Read values from CSV (Comma-
Separated Value) files.
File management (File I/O) Copy, move, rename, and delete
files using scripts.
Initialization File management Read and write strings or numbers
(INI files) to and from INI files.
List and Combo Box Add, edit, and manipulate list and
combo boxes.
Logging Log information to text files.
Miscellaneous Perform miscellaneous functions.
Network Toggle a client target to an
alternate server.
Panel Management Open, close, show, hide and/or print
panels.
Screen Navigation Manipulate the position of the
cursor.
Security Log users on and off.
Serial Communication (Com Ports) Communicate to devices attached to
serial ports on your computer.
Statistical Process Control (SPC) Manipulate, inspect, and store data.
Structured Query Language (SQL) Retrieve, update, and delete data in
relational databases with SQL
statements.
String Modify the content of strings.
System Access system-level features.
Trend Management Configure chart objects.
Video/Sound Add and control multimedia.
Web Perform web and internet-related
functions.
View script function parameters

(This topic applies only to Windows PC and QuickPanel View/Control targets. View
scripting functions by target indicates which functions each target supports. For a list of View
functions supported by QuickPanel targets, see QPScript Functions list.)

View scripting functions perform various actions and operations in an HMI


script. Many of these script functions use parameters for specifying an action
or operation in greater detail. Parameters are written in a standard format
that indicates its possible values. While the parameter descriptions indicate
those possible values, this format is summarized here.
Parameters enclosed in square brackets ("[" and "]") are optional. Other
parameters are required.
Parameter names themselves are composed of two parts:

● a prefix that describes the parameter type, and;


● a word that describes the parameter itself.

The following standard prefixes are used:

Prefix Description
activex The name of an ActiveX object (For Active Scripting, see the note
below.)
almgrp The name of an alarm group (For Active Scripting, see the note
below.)
almobj The name of an alarm object (For Active Scripting, see the note
below.)
device The name of a device (For Active Scripting, see the note below.)
loggrp The name of a logging group (For Active Scripting, see the note
below.)
module The name of a module (For Active Scripting, see the note below.)
pan The name of a graphical panel (For Active Scripting, see the note
below.)
num A literal number, analog variable, or discrete variable
strvar The name of a STRING variable (For Active Scripting, see the note
below.)
trnobj The name of a chart object
var An analog or BOOL variable (For Active Scripting, see the note
below.)
vardis A BOOL (discrete) variable (For Active Scripting, see the note below.)
trnobj The name of a chart object (For Active Scripting, see the note below.)
str A literal string in double quotation marks, or a STRING variable
Note: If you want a literal string to contain quotation marks within the text, they must be
escaped by typing a caret before each quote. For example, if the text is Motors are "ON",
the literal string would be: "Motors are ^"ON^""
Notes

● Parameters beginning with any of the following prefixes also accept a string expression
containing the name of the window or group required: almgrp, almobj, loggrp, trnobj, and
pan.
● When writing scripts in an Active Scripting language (such as VBScript), names of objects
and variables must be written as strings.
Active Scripting in View: an Overview

(Supported only on Windows PC targets and Intermediate or Loaded QuickPanel View/Control


targets.)
Note: View scripting is now run in a multi-threaded environment. For this reason, care should be
taken when using both ViewScript and VBScript in one project.

Active Scripting is a scripting system created by Microsoft to facilitate


common scripting functionality in a variety of applications—in this case, a
View HMI project. Active Scripting languages provide a significantly greater
degree of flexibility than the standard ViewScript language.
Active Scripting support in View has the following limitations:

● Only the VBScript language is supported.


● A VBScript variable defined locally in a script (with a DIM statement) is
also available for use in other scripts on the same target. Using the
same variable in more than one script can cause unpredictable results.
● VBScript is supported only on Windows PC targets and Intermediate and
Loaded models of QuickPanel View and QuickPanel Control targets.
For a list of QuickPanel View/Control models that support VBScript,
see QuickPanel View/Control Model Specifications.

View Preferences control the initial setting for a button script and the default
behavior for the INSERT key. You can specify the default scripting language
used by scripts in your application.
References to certain items work differently in an Active Scripting language
than in ViewScript, including:

● Variable references.
● Array element references.
● Structure element references.
● View function calls.

Note: All name parameters (for example, variable, panel, trend object, alarm object, graphical
object names) will be passed in as strings.

Validation of Active Scripting languages


VBScript and other Active Scripting languages are validated at run time. You
can also validate a project at any time during development to check:

● Syntax for View function calls.


● Syntax for variable, array, and structure element references.
● Limited checks for VBScript syntax.

Some of the VBScript syntax checks performed are:

● Redefinition of functions or subroutines already defined in a script library


is not allowed.
● Definitions of variables, constants, functions and subroutines must be
valid.
● Looping constructs must terminate properly.
● All local variables must be defined using the 'Dim' statement. This
means 'option explicit' is in effect.
● Functions and subroutines must be defined before they are called.

Running an Active Script


Application scripts and Panel scripts are scheduled and run using the
same activation strategies as View Scripts:

● On startup.
● On shutdown.
● On panel open.
● On panel close.
● Periodically.
● On condition.

Notes
● The above activation strategies do not apply to Global Function Library scripts.
● For more information, see View scripts or VBScripts.
View Scripting Functions by Target
The following table shows target support for Proficy View script functions:
QuickPanel
Function Group Function NT
View/Control
ActiveX ActiveXGetProperty §
ActiveXInvokeMethod §
ActiveXSetProperty §
Alarm Management AlarmAck § §
AlarmClear § §
AlarmClearAll § §
AlarmGroupCount § §
AlarmGroupCountAll § §
AlarmGrpAck § §
AlarmGroupEnable § §
AlarmFilter § §
AlarmFirst § §
AlarmLast § §
AlarmNext § §
AlarmPgDn § §
AlarmPgUp § §
AlarmPrev § §
AlarmPrint § §
AlarmPriority § §
AlarmVarAck § §
Animation ChangeBitmap § §
TriggerInput § §
Application Access (App ActivateApp § §
Control) AppExec § §
AppHelp §
AppShow § §
AppShow § §
SendKeys §
SendValue §
CSV File Management CSVCloseFile § §
CSVGetNumFields § §
CSVGetNumLines § §
CSVGetValue § §
CSVOpenFile § §
File management (File FileCopy § §
I/O) FileMove § §
FileRename § §
FileDelete § §
FileSetDemoMode § §
HttpCopy § §
HttpDelete § §
Initialization File IniForceIniPath §
Management (INI files) IniReadNumber §
IniReadString §
IniWriteNumber §
IniWriteString §
List and Combo Box lbAddString § §
lbDeleteString § §
lbDeleteStringAtIndex § §
lbEmpty § §
lbFillWithDirectory § §
lbFindString § §
lbFindStringExact § §
lbGetCount § §
lbGetCurSel § §
lbGetItemData § §
lbGetSelString § §
lbGetString § §
lbInsertString § §
lbSelectString § §
lbSetCurSel § §
lbSetItemData § §
Logging LogCloseFile § §
LogDate § §
LogElapsed § §
LogFileExists § §
LogNewFile § §
LogNewLine § §
LogOpenFile § §
LogPrintString § §
LogPrintValue § §
LogSetUseComma § §
LogTime § §
Miscellaneous Message § §
NetChangeServer § §
Random § §
ToggleDiscrete § §
Panel Management PanelClose § §
PanelHide § §
PanelIconize §
PanelIndex § §
PanelOpen § §
PanelPrint § §
PanelRestore §
PanelShow § §
Screen Navigation ScreenSelectObject §
ScreenSetCursorPos §
Security EditUserList § §
Logon § §
Logoff § §
Serial Communication ComPortClose § §
(Com Ports) ComPortFlush § §
ComPortGet § §
ComPortGetFile § §
ComPortGetHex § §
ComPortOpen § §
ComPortPut § §
ComPortPutFile § §
ComPortPutHex § §
Statistical Process SPCAddval § §
Control (SPC) SPCClearArray § §
SPCCreateArray § §
SPCDeleteArray § §
SPCGetVal § §
SPCMax § §
SPCMean § §
SPCVarianceMean § §
SPCMedian § §
SPCMin § §
SPCRange § §
SPCRangeMean § §
SPCSaveToFile § §
SPCStdDev § §
SPCStdDevMean § §
SPCSamples § §
SPCSum § §
SPCVariance § §
Structured Query dbConnect §
Language (SQL) dbDisconnect §
dbSQL §
dbFileSQL §
dbEndSQL §
dbFirstRecord §
dbGotoRecord §
dbLastError §
dbLastRecord §
dbNextRecord §
dbPrevRecord §
String CopyDateToString § §
CopyTimeToString § §
CopyUserToString § §
StringCompare § §
StringConCat § §
StringCopy § §
SubString § §
StringPos § §
StringLength § §
StringToNum § §
StringFromNum § §
ASCIIToDec § §
DecToASCII § §
HexStringFromNum § §
System AssignIndirect § §
AssignIndiFromStr § §
DeviceChangeDriver § §
GetDayOfWeek § §
GetDayOfYear § §
LogEvent § §
LogGroupEnable § §
ValidateRecipe § §
LoadRecipe § §
SaveRecipe § §
RestartWindows §
RunCommand § §
SetLanguage § §
SystemExit § §
Trend Management TrendClear § §
TrendContinueDisplay § §
TrendEdit § §
TrendPauseDisplay § §
TrendPrint § §
TrendSetRange § §
TrendSetRate § §
TrendTrigger § §
Video/Sound AviClose §
AviOpen §
AviPause §
AviPlay §
AviRewind §
Beep §
PlaySound § §*
Web PanelToBitmap § §
PanelToJPEG § §
SendEmail § §
RollOverDocument § §
* The QuickPanel View/Control hardware does not support this function. You can use it in your
scripts, but it will do nothing.
View Scripting Functions

ActiveX script functions

ActiveX script functions allow scripts to interact with ActiveX controls during
runtime. Properties for ActiveX objects are set in the Property Inspector and
depend on the ActiveX Control you select.
Notes:

● ActiveX script functions are supported only by Windows PC and Intermediate or Loaded
QuickPanel View/Control targets.
● ActiveX script functions can only be used on ActiveX controls embedded in a panel. You
cannot use these functions on ActiveX controls created within the script. Conversely, you
must use native Visual Basic functions on ActiveX controls created within a script.

The following ActiveX script functions are available:

Function Description
ActiveXGetProperty Used to retrieve the value of a particular ActiveX
control's property.
ActiveXSetProperty Used to change the value of a particular ActiveX
control's property.
ActiveXInvokeMethod Used to call an ActiveX control's method.
View Scripting Functions ActiveX

ActiveXGetProperty
Retrieves the value of an ActiveX control's property.
This value is returned through the varReturnVal parameter.
Supported by: Windows PC targets only
Note: The ActiveXGetProperty function must be used to get the properties of ActiveX controls
embedded in a graphical panel. You can not access ActiveX object properties directly in VBScript.

Active Scripting syntax


View.ActiveXGetProperty (strActivexObjectName, strPropertyName,
strVarReturnValName)

ViewScript syntax
ActiveXGetProperty ActivexObjectName, strPropertyName, varReturnVal

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strActivexObjectName ActivexObjectName The name of the ActiveX Container
Object that is configured in the
editor.
strPropertyName strPropertyName String expression indicating the
Property Name. It can represent a
nested property such as 'Font.Bold'
(where each parameter is
separated with a period, ".").
strVarReturnValName varReturnVal A Machine Edition variable that
holds the return value from the
script function.
Tip: Although View Runtime attempts to
convert the variable to match the type of
variable passed in, it is recommended that
the variable match the data type returned by
the ActiveX control.

Return Value
This function returns 1 if the value was retrieved successfully, 0 otherwise.

Comments
When using this function in an Active Scripting language (such as VBScript),
names of all items and variables in parameters must be written as string
expressions. Also, strVarReturnValName cannot refer to a variable that is
locally defined in VBScript with a DIM statement.
This script function is designed for scripts written in ViewScript. It is still
useable in scripts written in an Active Scripting language (such as VBScript),
but such languages typically include native support for ActiveX controls.

ViewScript Example
This sample retrieves the current selected date in the calendar control
'Calendar1' into the STRING variable 'CurrentValue'.
worked := ActiveXGetProperty Calendar1, "Value", CurrentValue
IF worked = 0
Message "Error. Could not get current value."
ENDIF

Active Scripting Example


This sample is the same as above, written in VBScript.
Dim worked
worked = View.ActiveXGetProperty ("Calendar1", "Value",
CurrentValue.Name)
If worked = 0 Then
View.Message "Error. Could not get current value."
End If

See Also
ActiveXSetProperty, ActiveXInvokeMethod
View Scripting Functions ActiveX

ActiveXInvokeMethod
Calls an ActiveX control's method.
Supported by: Windows PC targets only
Note: The ActiveXInvokeMethod function must be used to invoke the methods of ActiveX controls
embedded in a graphical panel. You can not invoke ActiveX object methods directly in VBScript.

Active Scripting syntax


View.ActiveXInvokeMethod strActivexObjectName, strMethodName,
strParameters, strVarReturnValueName

ViewScript syntax
ActiveXInvokeMethod ActivexObjectName, strMethodName,
strParameters, varReturnValue

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strActivexObjectName ActivexObjectName The name of the ActiveX Object
that is configured in the editor.
strMethodName strMethodName String expression specifying the
name of the method to invoke. It
can indicate a nested method
such as "Calendar.Today" (where
each method or property is
separated with a period, ".").
strParameters strParameters String expression specifying a
comma-separated string, which
includes values of parameters for
the method. These values can be
either string constants or STRING
variables.
Tip: When using string constants, make
sure you separate the parameter values
correctly, enclosing the entire comma-
separated list within quotation marks.
When using ViewScript, quotation marks
within the parameter list should be
preceded with the ^ character, as in
"^"hello world^"". When using Active
Script, quotation marks within the
parameter list should be preceded the "
character, as in """hello world""". Refer to
the examples below for a further
explanation.

strVarReturnValueName varReturnValue The Machine Edition variable that


is to hold the return value from
the method.

Return Value
This function returns 1 if the method was called successfully, 0 otherwise.

Comments
When using this function in an Active Scripting language (such as VBScript),
names of all items and variables in parameters must be written as string
expressions. Also, strVarReturnValueName cannot refer to a variable that is
locally defined in VBScript with a DIM statement.

ViewScript Example
This ViewScript sample sets the calendar control 'Calendar1' to today’s date.
The variable ReturnValue is there just in case the method returns a value.
worked := ActiveXInvokeMethod Calendar1, "Today", "", ReturnValue
IF worked = 0
Message "Error. Could not set Calendar1 to today’s date."
ENDIF

Active Scripting Example


This sample is the same as above, written in VBScript.
Dim worked
worked = View.ActiveXInvokeMethod ("Calendar1", "Today", "",
ReturnValue.Name)
If worked = 0 Then
View.Message "Error. Could not set Calendar1 to today’s date."

End If
See Also
ActiveXGetProperty, ActiveXSetProperty
View Scripting Functions ActiveX

ActiveXSetProperty
Sets the value of an ActiveX control's property.
This value is set through the varSetVal.
Supported by: Windows PC targets only
Note: The ActiveXSetProperty function must be used to set the properties of ActiveX controls
embedded in a graphical panel. You can not set ActiveX object properties directly in VBScript.

Active Scripting syntax


View.ActiveXSetProperty strActivexObjectName, strPropertyName,
strVarSetValName

ViewScript syntax
ActiveXSetProperty ActivexObjectName, strPropertyName, varSetVal

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strActivexObjectName ActivexObjectName The name of the ActiveX Container
Object that is configured in the
editor.
strPropertyName strPropertyName The Property Name is a string
value. It can represent a nested
property such as Font.Bold (where
each property is separated by a ' .
').
Note: The parameter can be a literal or a
variable.
strVarSetValName varSetVal The Machine Edition variable to
whose value you want to set the
property.

Return Value
This function returns 1 if the value was set successfully, 0 otherwise.

Comments
When using this function in an Active Scripting language (such as VBScript),
names of all items and variables in parameters must be written as string
expressions. Also, strVarSetValName cannot refer to a variable that is locally
defined in VBScript with a DIM statement.

ViewScript Example
This ViewScript sample sets the ActiveX checkbox object 'Check1' to on (the
value of the discrete variable SetValue).
MySetValue := 1
worked := ActiveXSetProperty Check1, "Value", MySetValue
IF worked = 0
Message "Error. Could not set the checkbox Check1."
ENDIF

Active Scripting Example


This sample is the same as above, written in VBScript.
Dim worked
MySetValue.Value = 1
worked = View.ActiveXSetProperty ("Check1", "Value",
MySetValue.Name)
If worked = 0 Then
View.Message "Error. Could not set the checkbox Check1."
End If

See Also
ActiveXGetProperty, ActiveXInvokeMethod
View Scripting Functions

Alarm Management script functions

Alarm management functions allow scripts to interact with alarm messages,


Alarm Display objects and Alarm groups. This includes functions for
enabling specific types of alarms and for acknowledging alarms assigned to a
specified variable or Variable Alarm group.
Note: All Alarm management functions support the use of remote alarm groups as parameters with
the correct syntax.
Warning: Alarm object names must be used without quotation marks around them.

The following Alarm management functions are available.


Function Description
AlarmAck Prompts for acknowledgment of the selected alarm
message.
AlarmClear Clears the selected alarm message.
AlarmClearAll Clears all inactive alarm messages.
AlarmGroupCount Counts the number of active alarm messages in a
Variable alarm group.
AlarmGroupCountAll Counts all active alarm messages in a Variable Alarm
group.
AlarmGrpAck Acknowledges active alarm messages in a Variable
Alarm group.
AlarmGroupEnable Enables or disables certain alarm types for a Variable
Alarm group.
AlarmFilter Changes the Variable Alarm group associated with an
Alarm Display object.
AlarmFirst Moves the cursor to the first alarm in an Alarm
Display object.
AlarmLast Moves the cursor to the last alarm in an Alarm Display
object.
AlarmNext Moves the cursor to the next alarm in an Alarm
Display object.
AlarmPgDn Moves the cursor one page down in an Alarm Display
object.
AlarmPgUp Moves the cursor one page up in an Alarm Display
object.
AlarmPrev Moves the cursor to the previous alarm in an Alarm
Display object.
AlarmPrint Prints all alarms displayed in an Alarm Display object.
AlarmPriority Changes the priority level of an Alarm Display object,
specifying which alarms are to be displayed.
AlarmVarAck Acknowledges active alarm messages for a specific
variable.
View Scripting Functions Alarm Management

AlarmAck
Acknowledges a selected active alarm message, with the option of having the
user add a comment describing the cause of the alarm or how it was
resolved. If the Alarm Object's 'AckMessage' property is set to TRUE, the user
is presented with a dialog box to enter a comment for the currently selected
alarm and the Alarm status is changed to 'Acknowledged'. If the 'AckMessage'
property is set to FALSE, the alarm is acknowledged without prompting the
user for comments.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.AlarmAck strAlmobjName

ViewScript syntax
AlarmAck almobjName

Parameters (see Naming Conventions)


Active ViewScript Description
Scripting
strAlmobjName AlmobjName The name of the Alarm Display object.

Return Value
None

Comments
This command is only valid for alarm displays whose Show History property is
False (that is, alarm displays that are in Alarm Summary mode, not Alarm
History mode).
When using this function in an Active Scripting language (such as VBScript),
names of all items and variables in parameters must be written as string
expressions.
Warning: When viewing QuickPanel View/Control HMI graphical panels remotely over the web (see
Remote Viewing of View Runtime), any dialog boxes that are opened because of actions
performed remotely on the HMI will not be closed on the QuickPanel View/Control display. This
will eventually cause the HMI application to fail. If you want to use a script function that opens a
dialog box on a QuickPanel View/Control target, it is highly recommended that you do not allow
users to operate the HMI remotely.

ViewScript Example
The following ViewScript sample prompts the operator for comments before
acknowledging selected alarms within the 'Press1Alarms' alarm object.
AlarmAck Press1Alarms

Active Scripting Example


This sample is the same as above, written in VBScript.
View.AlarmAck "Press1Alarms"

See Also
AlarmGroupCount, AlarmGroupCountAll, AlarmGrpAck, AlarmTagAck
View Scripting Functions Alarm Management

AlarmClear
Clears an inactive alarm entry in an Alarm Display object.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.AlarmClear strAlmobjName

ViewScript syntax
AlarmClear almobjName

Parameters (see Naming Conventions)


Active ViewScript Description
Scripting
strAlmobjName AlmobjName The name of the Alarm Display object.

Return Value
None

Comments
This function is valid only for alarm displays whose Show History property is
True (that is, alarm displays that are set to Alarm History mode).
This function clears the currently-selected alarm entry. Since alarm messages
cannot be recovered, you may wish to implement security mechanisms (such
as the use of Security script functions) to ensure that information is not lost.
When using this function in an Active Scripting language (such as VBScript),
names of all items and variables in parameters must be written as string
expressions.

ViewScript Example
This ViewScript sample clears the alarm object 'Press1Alarms' if the access
level is greater than 100.
If (#AccessLevel > 100)
AlarmClear Press1Alarms
Endif

Active Scripting Example


This sample is the same as above, written in VBScript.
If (AccessLevel.Value > 100) Then
View.AlarmClear "Press1Alarms"
End If

See Also
AlarmClearAll, AlarmFilter, AlarmPriority
View Scripting Functions Alarm Management

AlarmClearAll
Clears all inactive alarms within an Alarm Display object.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.AlarmClearAll strAlmobjName

ViewScript syntax
AlarmClearAll almobjName

Parameters (see Naming Conventions)


Active ViewScript Description
Scripting
strAlmobjName AlmobjName The name of the Alarm Display object.

Return Value
None

Comments
This function is valid only for alarm displays whose Show History property is
True (that is, alarm displays that are set to Alarm History mode).
This function clears all alarm messages in the specified alarm display. Since
cleared alarm messages cannot be recovered, you may wish to implement
security mechanisms (such as the use of Security script functions) to ensure
that information is not lost.
When using this function in an Active Scripting language (such as VBScript),
names of all items and variables in parameters must be written as string
expressions.

ViewScript Example
This ViewScript sample clears all inactive alarms in the alarm object
'Press1Alarms'.
AlarmClearAll Press1Alarms

Active Scripting Example


This sample is the same as above, written in VBScript.
View.AlarmClearAll "Press1Alarms"

See Also
AlarmClear, AlarmFilter, AlarmPriority
View Scripting Functions Alarm Management

AlarmFilter
Changes the Variable Alarm Group associated with an Alarm Display
object.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.AlarmFilter strAlmobjName [, strNewFilter]

ViewScript syntax
AlarmFilter almobjName [, strNewFilter]

Parameters (see Naming Conventions)


Active ViewScript Description
Scripting
strAlmobjName AlmobjName The name of the Alarm Display object.
strNewFilter strNewFilter (Optional) String expression containing the
name of the Variable Alarm Group to
display. Use either a literal string or a STRING
variable.

Return Value
None

Comments
An Alarm Display object displays all appropriate alarm messages for its
associated Variable Alarm Group (and its subgroups), as well as messages
for all Bit Alarm Groups and Word Alarm Groups on the target.
Note: You cannot specify a bit alarm or word alarm group in strNewFilter. All bit alarm and word
alarm messages are always displayed in an Alarm Display object, regardless of the selected
variable alarm group.

When using this function in an Active Scripting language (such as VBScript),


names of all items and variables in parameters must be written as string
expressions.
Warning: When viewing QuickPanel View/Control HMI graphical panels remotely over the web
(see Remote Viewing of View Runtime), any dialog boxes that are opened because of actions
performed remotely on the HMI will not be closed on the QuickPanel View/Control display. This
will eventually cause the HMI application to fail. If you want to use a script function that opens a
dialog box on a QuickPanel View/Control target, it is highly recommended that you do not allow
users to operate the HMI remotely.

ViewScript Examples
Example 1: The following ViewScript example displays the Alarm Filter
Selection dialog box to allow a user to change the variable alarm group that
is displayed in the 'AlarmObject1' alarm object.
AlarmFilter AlarmObject1
Example 2: The following displays the 'AlarmGroup02' variable alarm group in
the 'AlarmObject1' alarm object.
AlarmFilter AlarmObject1, "AlarmGroup02"

Active Scripting Examples


Example 1: The following VBScript example displays the Alarm Filter
Selection dialog box to allow a user to change the variable alarm group that
is displayed in the 'AlarmObject1' alarm object.
View.AlarmFilter "AlarmObject1"
Example 2: The following VBScript example displays the 'AlarmGroup02'
alarm group in the 'AlarmObject1' alarm object.
View.AlarmFilter "AlarmObject1", "AlarmGroup02"

See Also
AlarmGroupCount, AlarmGroupCountAll, AlarmGrpAck, AlarmGroupEnable,
AlarmPriority
View Scripting Functions Alarm Management

AlarmFirst
Selects the first alarm message displayed in an Alarm Display object.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.AlarmFirst strAlmobjName

ViewScript syntax
AlarmFirst almobjName

Parameters (see Naming Conventions)


Active ViewScript Description
Scripting
strAlmobjName AlmobjName The name of the Alarm Display object.

Return Value
None

Comments
When using this function in an Active Scripting language (such as VBScript),
names of all items and variables in parameters must be written as string
expressions.

ViewScript Example
The following ViewScript example selects the first alarm in the 'CriticalAlarms'
alarm object and acknowledges it.
AlarmFirst CriticalAlarms
AlarmAck CriticalAlarms
Active Scripting Example
This example is the same as above, written in VBScript.
View.AlarmFirst "CriticalAlarms"
View.AlarmAck "CriticalAlarms"
See Also
AlarmLast, AlarmNext, AlarmPgDn, AlarmPgUp, AlarmPrev
View Scripting Functions Alarm Management

AlarmGroupCount
Counts the active alarms in a Variable Alarm Group and its subgroups. This
does not include acknowledged alarms.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.AlarmGroupCount strAlmgrpName

ViewScript syntax
AlarmGroupCount almgrpName

Parameters (see Naming Conventions)


Active ViewScript Description
Scripting
strAlmgrpName AlmgrpName The name of the Variable Alarm Group
whose active variables you want to count.

Return Value
The number of active alarms in the specified Variable Alarm group.

Comments
This function cannot be used to count the number of active alarms in a Bit
Alarm or Word Alarm group.
When using this function in an Active Scripting language (such as VBScript),
names of all items and variables in parameters must be written as string
expressions.

ViewScript Example
The following ViewScript example stores the total number of system wide
active alarm messages in the 'AlarmCount' variable.
AlarmCount := AlarmGroupCount RootAlarmGroup

Active Scripting Example


This sample is the same as above, written in VBScript.
AlarmCount.Value = View.AlarmGroupCount ("RootAlarmGroup")

See Also
AlarmGroupCountAll, AlarmGrpAck, AlarmGroupEnable
View Scripting Functions Alarm Management

AlarmGroupCountAll
Counts the total number of active and acknowledged alarm messages based
on a Variable Alarm Group.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.AlarmGroupCountAll [strAlmgrpName]

ViewScript syntax
AlarmGroupCountAll [AlmgrpName]

Parameters (see Naming Conventions)


Active ViewScript Description
Scripting
strAlmgrpName AlmgrpName (Optional) The name of the alarm group to
count.

Return Value
The number of alarms in the specified alarm group.

Comments
This function does not include alarm messages based on a Bit Alarm or
Word Alarm group.
When using this function in an Active Scripting language (such as VBScript):

● View.AlarmGroupCountAll "" is valid, and all Variable Alarm groups will


be counted.
● Names of all items and variables in parameters must be written as
string expressions.

ViewScript Example
The following ViewScript example counts all alarms in the 'CriticalAlarms'
alarm group object and stores the result in the 'AlarmCount' variable. It then
counts all active alarm objects and stores the result in the 'AlarmCountX'
variable. It uses these results to calculate the number of acknowledged alarm
objects.
AlarmCount := AlarmGroupCountAll CriticalAlarms
AlarmCountX := AlarmGroupCount CriticalAlarms
AckCount := AlarmCount - AlarmCountX

Active Scripting Example


This sample is the same as above, written in VBScript.
AlarmCount.Value = View.AlarmGroupCountAll ("CriticalAlarms")
AlarmCountX.Value = View.AlarmGroupCount ("CriticalAlarms")
AckCount.Value = AlarmCount.Value - AlarmCountX.Value

See Also
AlarmGroupCount, AlarmGrpAck, AlarmGroupEnable
View Scripting Functions Alarm Management

AlarmGroupEnable
Enables or disables alarm logging or a specific type of alarm for an entire
Variable Alarm Group. For example, you could disable all LoLo alarms or
enable alarm logging for variables in a variable alarm group.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.AlarmGroupEnable strAlmgrpGroupName, numAlarmParameter,
numNewValue

ViewScript syntax
AlarmGroupEnable AlmgrpGroupName, numAlarmParameter,
numNewValue

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strAlmgrpGroupName AlmgrpGroupName The name of the Variable Alarm
Group.
numAlarmParameter numAlarmParameter Integer expression indicating the
type of alarm to enable or disable.
Valid values are:
0 = AlarmLogging
1 = LoLo alarm
2 = Lo alarm (or when LO for
discrete tags)
3 = Hi alarm (or when HI for
discrete tags)
4 = HiHi alarm
5 = Minor deviation %
6 = Major deviation %
7 = Minor deviation fixed
8 = Major deviation fixed
9 = Rate of Change
numNewValue numNewValue Integer expression. Set to 0 to
disable the indicated alarms; set
to 1 to enable them.

Return Value
None
Comments
Variable Alarm Groups are organized into a tree structure. Enabling or
disabling a setting for one variable alarm group automatically enables or
disables the same setting for all of its subgroups. This may cause issues if
specified alarm types are not configured for variables within that group or its
subgroups.
For example, if HiHi alarms are enabled within a Variable Alarm Group named
MyAlarms1, all variables within that group are enabled, regardless of their
state at application startup. This can cause problems if a variable within that
group does not have a HiHi limit configured. When using AlarmGroupEnable
to toggle alarms of specified types, you should assign variables should to
Variable Alarm Groups based on the types of alarms that you want to enable
or disable.
When using this function in an Active Scripting language (such as VBScript),
names of all items and variables in parameters must be written as string
expressions.
ViewScript Example
The following ViewScript example enables alarm logging for the alarm group
object RootAlarmGroup.
the logging of all variables in your application.
AlarmGroupEnable RootAlarmGroup, 0, 1

Active Scripting Example


This sample is the same as above, written in VBScript.
View.AlarmGroupEnable "RootAlarmGroup", 0, 1

See Also
AlarmGroupCount, AlarmGroupCountAll, AlarmGrpAck
View Scripting Functions Alarm Management

AlarmGrpAck
Acknowledges all active alarms in a Variable Alarm Group. By default, a
dialog box appears to let the operator to enter an Acknowledgment comment;
this can be disabled with the numSkipAckPrompt parameter.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.AlarmGrpAck strAlmgrpGroupToAck [, numSkipAckPrompt]

ViewScript syntax
AlarmGrpAck AlmgrpGroupToAck [, numSkipAckPrompt]

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strAlmgrpGroupToAck AlmgrpGroupToAck The name of the Variable Alarm
Group whose alarm messages you
want to acknowledge.
numSkipAckPrompt numSkipAckPrompt (Optional) Integer expression. If 0
(the default), the user is prompted
to enter a comment; if any other
value, the user is not.

Return Value
None

Comments
This function does not acknowledge alarm messages based on Bit Alarm
groups or Word Alarm groups.
When using this function in an Active Scripting language (such as VBScript),
names of all items and variables in parameters must be written as string
expressions.
Warning: When viewing QuickPanel View/Control HMI graphical panels remotely over the web
(see Remote Viewing of View Runtime), any dialog boxes that are opened because of actions
performed remotely on the HMI will not be closed on the QuickPanel View/Control display. This
will eventually cause the HMI application to fail. If you want to use a script function that opens a
dialog box on a QuickPanel View/Control target, it is highly recommended that you do not allow
users to operate the HMI remotely.

ViewScript Example
The following ViewScript example acknowledges all alarm objects in the
target application.
AlarmGrpAck RootAlarmGroup

Active Scripting Example


This sample is the same as above, written in VBScript.
View.AlarmGrpAck "RootAlarmGroup"

See Also
AlarmAck, AlarmGroupCount, AlarmGroupCountAll, AlarmGroupEnable,
AlarmTagAck
View Scripting Functions Alarm Management

AlarmLast
Selects the last alarm displayed in an Alarm Display object.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.AlarmLast strAlmobjName

ViewScript syntax
AlarmLast AlmobjName

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strAlmobjName AlmobjName The name of the Alarm Display object.

Return Value
None

Comments
When using this function in an Active Scripting language (such as VBScript),
names of all items and variables in parameters must be written as string
expressions.

ViewScript Example
The following ViewScript example selects the last alarm in the 'CriticalAlarms'
alarm object and acknowledges it.
AlarmLast CriticalAlarms
AlarmAck CriticalAlarms

Active Scripting Example


This sample is the same as above, written in VBScript.
View.AlarmLast "CriticalAlarms"
View.AlarmAck "CriticalAlarms"
See Also
AlarmAck, AlarmFirst, AlarmNext, AlarmPgDn, AlarmPgUp, AlarmPrev
View Scripting Functions Alarm Management

AlarmNext
Selects the alarm immediately following the currently selected alarm in an
Alarm Display object.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.AlarmNext strAlmObjName

ViewScript syntax
AlarmNext almobjName

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strAlmObjName almobjName The name of the Alarm Display object.

Return Value
None

Comments
Use this function to scroll alarm objects using custom buttons. This is useful
for the touch screen feature of QuickPanel View/Control units.
When using this function in an Active Scripting language (such as VBScript),
names of all items and variables in parameters must be written as string
expressions.

ViewScript Example
The following ViewScript example selects the alarm below the currently
selected alarm in the 'PumpAlarms' alarm object:
AlarmNext PumpAlarms

Active Scripting Example


This sample is the same as above, written in VBScript.
View.AlarmNext "PumpAlarms"

See Also
AlarmFirst, AlarmLast, AlarmPgDn, AlarmPgUp, AlarmPrev
View Scripting Functions Alarm Management

AlarmPgDn
Scrolls the displayed alarm list in an Alarm Display object down by one
page. A page is defined as the number of alarms that fit on a single screen.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.AlarmPgDn strAlmObjName

ViewScript syntax
AlarmPgDn almobjName

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strAlmObjName almobjName The name of the alarm object.

Return Value
None

Comments
Use this function to scroll alarm objects using custom buttons. This is useful
for the touch screen feature of QuickPanel View/Control units.
When using this function in an Active Scripting language (such as VBScript),
names of all items and variables in parameters must be written as string
expressions.

ViewScript Example
The following ViewScript example scrolls the 'PumpAlarms' alarm object down
one page:
AlarmPgDn PumpAlarms

Active Scripting Example


This sample is the same as above, written in VBScript.
View.AlarmPgDn "PumpAlarms"

See Also
AlarmFirst, AlarmLast, AlarmNext, AlarmPgUp, AlarmPrev
View Scripting Functions Alarm Management

AlarmPgUp
Scrolls the displayed alarm list in an Alarm Display object up by one page.
A page is defined as the number of alarms that fit on a single screen.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.AlarmPgUp strAlmObjName

ViewScript syntax
AlarmPgUp almobjName

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strAlmObjName almobjName The name of the alarm object.

Return Value
None

Comments
When using this function in an Active Scripting language (such as VBScript),
names of all items and variables in parameters must be written as string
expressions.

ViewScript Example
The following ViewScript example scrolls the 'PumpAlarms' alarm object up by
one page:
AlarmPgUp PumpAlarms

Active Scripting Example


This sample is the same as above, written in VBScript.
View.AlarmPgUp "PumpAlarms"

See Also
AlarmFirst, AlarmLast, AlarmNext, AlarmPgDn, AlarmPrev
View Scripting Functions Alarm Management

AlarmPrev
Selects the alarm immediately before the currently selected alarm in the
Alarm Display object.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.AlarmPrev strAlmObjName

ViewScript syntax
AlarmPrev almobjName

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strAlmObjName almobjName The name of the alarm object.

Return Value
None

Comments
When using this function in an Active Scripting language (such as VBScript),
names of all items and variables in parameters must be written as string
expressions.

ViewScript Example
The following ViewScript example selects the alarm above the currently
selected alarm in the 'PumpAlarms' alarm object:
AlarmPrev PumpAlarms

Active Scripting Example


This sample is the same as above, written in VBScript.
View.AlarmPrev "PumpAlarms"

See Also
AlarmFirst, AlarmLast, AlarmNext, AlarmPgDn, AlarmPgUp
View Scripting Functions Alarm Management

AlarmPrint
Prints all alarms displayed in an Alarm Display object. Alarms are printed
in the same order they are displayed on the HMI. The default printer is used
to print alarms.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.AlarmPrint strAlmObjName

ViewScript syntax
AlarmPrint almobjName

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strAlmObjName almobjName The name of the Alarm Display object.

Return Value
None

Comments
You can print alarms from Alarm Display objects set to Alarm Summary mode
(with its Show History property set to False) and in Alarm History mode (with
Show History set to True).
When using this function in an Active Scripting language (such as VBScript),
names of all items and variables in parameters must be written as string
expressions.

ViewScript Example
The following ViewScript example prints all alarms displayed in the
'FurnaceAlarms' alarm object.
AlarmPrint FurnaceAlarms

Active Scripting Example


This sample is the same as above, written in VBScript.
View.AlarmPrint "FurnaceAlarms"

See Also
AlarmPrev, AlarmPriority
View Scripting Functions Alarm Management

AlarmPriority
Sets the priority level of a given alarm object. When used without the second
parameter, a dialog appears allowing the user to enter a priority level. View
can classify from 0 to 999 priority levels of alarms. When using this function,
an alarm display object will display only those alarms with a priority less than
or equal to the specified priority level.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.AlarmPriority strAlmObjName [, numNewPriority]

ViewScript syntax
AlarmPriority almobjName [, numNewPriority]

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strAlmObjName almobjName The name of the alarm object.
numNewPriority numNewPriority (Optional) Integer expression indicating
the priority level. This can be from 0
through 999. You can use a literal integer
value or a variable.

Return Value
None.

Comments
The priority for a variable's alarms are specified in the variable's Alarming
Priority property (in the Alarms tab of the Inspector). Each variable can have
a different priority.
Alarm messages based on Word Alarm Groups and Bit Alarm Groups are
considered to have a priority of 0. That is, bit alarm messages and word
alarm messages have the highest priority and are always displayed.
When using this function in an Active Scripting language (such as VBScript),
names of all items and variables in parameters must be written as string
expressions.

ViewScript Examples
Example 1: The following ViewScript example prompts the user to specify a
priority for the 'AlarmObject1' alarm object.
AlarmPriority AlarmObject1
Example 2: The following ViewScript example sets the priority of
"AlarmObject1" to 500.
AlarmPriority AlarmObject1, 500
Example 3: The following ViewScript example sets the priority of
'AlarmObject1' to the value of 'PriorityVariable'.
AlarmPriority AlarmObject1, PriorityVariable

Active Scripting Examples


Example 1: The following VBScript example prompts the user to specify a
priority for the 'AlarmObject1' alarm object.
View.AlarmPriority "AlarmObject1"
Example 2: The following VBScript example sets the priority of
"AlarmObject1" to 500.
View.AlarmPriority "AlarmObject1", 500
Example 3: The following VBScript example sets the priority of 'AlarmObject1'
to the value of 'PriorityVariable'.
View.AlarmPriority "AlarmObject1", PriorityVariable.Value

See Also
AlarmFilter
View Scripting Functions Alarm Management

AlarmVarAck
Acknowledges all active Variable Alarms for a specified variable, unless the
currently logged-in operator has no acknowledgment rights.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.AlarmVarAck strVarToAckName

ViewScript syntax
AlarmVarAck varToAck

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strVarToAckName varToAck The Machine Edition variable for which you
want all active alarms acknowledged.

Return Value
None

Comments
This function does not acknowledge alarm messages based on Bit Alarm
groups or Word Alarm groups.
When using this function in an Active Scripting language (such as VBScript),
names of all items and variables in parameters must be written as string
expressions. Also, strVarToAckName cannot refer to a variable that is locally
defined in VBScript with a DIM statement.

ViewScript Example
The following ViewScript example acknowledges all active alarms for the
'FurnaceTemp' variable.
AlarmVarAck FurnaceTemp

Active Scripting Example


This sample is the same as above, written in VBScript.
View.VarAck FurnaceTemp.Name

See Also
AlarmAck, AlarmGrpAck
View Scripting Functions

Animation script functions

Animation script functions are used to execute animation operations using a


script. For more information on configuring animation in your HMI, see
Animation: an Overview.
The following Animation Functions are available:
Function Description
ChangeBitmap Replaces an image with another image from your local or
network drive.
TriggerInput Displays an input dialog box allowing the user to enter a
value.
View Scripting Functions Animation

ChangeBitmap
Replaces an image object with another bitmap that's stored on your local or
network drive. Image objects are created using the Image tool in the
Graphical Editor.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.ChangeBitmap strPanelName, strObjName, strBmpFileName

ViewScript syntax
ChangeBitmap panName, strobjName, strBmpFileName

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strPanelName panName The name of the panel where the image
object is located.
strObjName strobjName The name of the image object you want to
replace. This is indicated by the image
object's Name property in the Inspector.
strBmpFileName strBmpFileName String expression containing the path and
filename of the image you want to replace
the object with. This can be a Windows
bitmap file (*.BMP) or a JPEG image
(*.JPG, *.JPEG).

Comments
Before you can use this function, the Image Object you want to replace must
be animated. It can be animated with purposeful animation or animation that
does nothing. For example, enable Visibility Animation and type the number 1
in the expression field so the object is always visible.
If you plan to change images of different sizes, ensure that the original
Image Object is larger than any other image you want to display. This is
important since the image may overlap with other objects in the window.
Note: When changing images based on *.BMP files (Windows bitmaps), the new image is drawn
with the same dimensions as the old image. When changing images based on *.JPG or *.JPEG
files (JPEG images), the new image is drawn based on the dimensions of the new image.

When using this function in an Active Scripting language (such as VBScript),


names of all items and variables in parameters must be written as string
expressions.

ViewScript Example
The following ViewScript example replaces the image object 'Pump_On' in the
'WaterFilter' panel with the image from the file "PumpError.bmp".
ChangeBitmap WaterFilter, "Pump_On", "c:\appbmp\PumpError.bmp"

Active Scripting Example


This sample is the same as above, written in VBScript.
View.ChangeBitmap
"WaterFilter", "Pump_On", "c:\appbmp\PumpError.bmp"
View Scripting Functions Animation

TriggerInput
Activates input animation in a script directly from a variable, without
animating an object. You can activate an input dialog box to input a new value
for the variable.
The TriggerInput script function accepts number variables, text variables and
discrete variables. However, the numLoLimit and numHiLimit parameters only
accept number variables.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.TriggerInput strVarName, strInputString [, numLoLimit,
numHiLimit] [, numBOOLUsePasswordMask]

ViewScript syntax
TriggerInput varName, strInputString [, numLoLimit] [, numHiLimit] [,
usePasswordMask]

Parameters (see Naming Conventions)


Active Scripting1 ViewScript Description
strVarName varName The name of the Machine
Edition variable in which the
new value is to be stored.
strInputString strInputString String expression indicating text
that should be placed in the
title bar of the input dialog box.
numLoLimit numLoLimit (Optional) The lowest allowable
value. (Integer/Real variables
only)
numHiLimit numHiLimit (Optional) The highest
allowable value. (Integer/Real
variables only)
numBOOLUsePasswordMask usePasswordMask (Optional) Integer expression,
for STRING variables only. If
usePasswordMask is a non-zero
value, then user string input is
masked with asterisks ("*"). If
it is 0, then user string input is
displayed as normal.
Note: If usePasswordMask is specified,
you must also include values for
numLoLimit and numHiLimit. These
values will, however, be ignored.

Return Value
None

Comments
When using this function in an Active Scripting language (such as VBScript),
names of all items and variables in parameters must be written as string
expressions. Also, strVarName cannot refer to a variable that is locally defined
in VBScript with a DIM statement.
Warning: When viewing QuickPanel View/Control HMI graphical panels remotely over the web
(see Remote Viewing of View Runtime), any dialog boxes that are opened because of actions
performed remotely on the HMI will not be closed on the QuickPanel View/Control display. This
will eventually cause the HMI application to fail. If you want to use a script function that opens a
dialog box on a QuickPanel View/Control target, it is highly recommended that you do not allow
users to operate the HMI remotely.

ViewScript Examples
Example 1: The following ViewScript example opens the input dialog box so
you can change the value of the variable 'TempSetPoint' to a value between 5 -
290.
TriggerInput TempSetPoint, "Enter a new set point:", 5, 290

Example 2: The following ViewScript example opens the input dialog box to
request a password from the user. The password is masked with asterisks.
TriggerInput varPassword, "Please enter the password:", 0, 0, 1

Active Scripting Examples


Example 1: The following VBScript example opens the input dialog box so you
can change the value of the variable 'TempSetPoint' to a value between 5 -
290.
View.TriggerInput TempSetPoint.Name, "Enter a new set point:", 5, 290

Example 2: The following VBScript example opens the input dialog box to
request a password from the user. The password is masked with asterisks.
View.TriggerInput varPassword.Name, "Please enter the password:", 0,
0, 1
View Scripting Functions

Application Access script functions

Application Access functions let View scripts launch other Microsoft Windows
applications and send keystroke commands to them.
The following Application Access Functions are available:
Function Description
ActivateApp Brings a specified Windows application to the foreground.
AppExec Starts or runs another Windows application.
AppHelp Launches Winhelp with a help file with a specific topic.
AppShow Changes how a Windows application appears on the screen.
SendKeys Sends keystrokes to the active Windows application.
SendValue Sends a formatted data value to the active Windows application.
View Script Functions Application Access

ActivateApp
Brings a selected application to the foreground. Specify the application using
a character string enclosed in quotes. This string must match the panel title
of the application you want to activate.
Support for class name search is available. This lets you specify an
application by its class name, which tends to be more stable than the panel
name.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.ActivateApp strAppTitleOrClassName [, numSearchForClassFlag]

ViewScript syntax
ActivateApp strAppTitleOrClassName [, numSearchForClassFlag]

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strAppTitleOrClassName strAppTitleOrClassName String expression indicating
the windows title or class
name. Use either a literal
string or a STRING variable.
numSearchForClassFlag numSearchForClassFlag (Optional) Integer
expression. If 1,
strAppTitleOrClassName
specifies a class name; if 0 it
specifies a title.
Note: The class name is typically the same as the executable name.

Return Value
0 = Successful
1 = Failure

Comments
This command is typically used in conjunction with SendKeys and SendValues
commands. The application must be activated before sending keys to it.
When using this function in an Active Scripting language (such as VBScript),
names of all items and variables in parameters must be written as string
expressions.

ViewScript Example
The following ViewScript example activates TrendX. If unsuccessful, it
displays an error message.
retVal := ActivateApp "TRENDX", 1
If retVal = 0
Message "Unable to activate trend module."
ENDIF

Active Scripting Example


This sample is the same as above, written in VBScript.
retVal.Value = View.ActivateApp ("TRENDX", 1)
If retVal = 0 Then
View.Message "Unable to activate trend module."
End If

See Also
AppExec, AppHelp, AppShow, SendKeys, SendValue
View Scripting Functions Application Access

AppExec
Starts another Windows (or DOS) application. You must provide the full path
and command line parameters for the application to launch.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.AppExec strFileName [, numStartMode]

ViewScript syntax
AppExec strFileName [, numStartMode]

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strFileName strFileName String expression specifying the application
filename along with any command line
parameters. Use either a literal string or a
STRING variable.
numStartMode numStartMode (Optional) Integer indicating how the
application must open. Valid options are:
0=Hidden Window
1=Normal Window (default)
2=Minimized Window
3=Maximized Window
4=Don't activate
5=Normal (same as 1)
6=Minimized
7=Minimized and not active
Note: If numShowMode is outside the 0-7 range, it will
default to 1 (Normal).

Comments
You can use AppExec to execute shell or DOS commands by calling the
command interpreter (CMD.EXE) with the "/c" option.
If path information is used as (for example) command line arguments, the
current directory is assumed to be the following:

● On Windows PC computers, this is typically "C:\Program Files\GE


IP\Proficy Machine Edition\fxView\Runtime\NT".
● On QuickPanel View/Control units, this is typically the
root directory.

ViewScript Example
The following ViewScript example launches Windows Notepad in maximized
mode with a text file named "readme.txt" in the Temp directory on drive C:
AppExec "Notepad.exe c:\Temp\readme.txt", 3
The following ViewScript example executes a DOS shell command that sends
the contents of a text file named "test.txt" on drive C to a printer at IP
Address 5.6.7.8:
AppExec "cmd /c type c:\test.txt > \\5.6.7.8\HPLaserJet6P"

Active Scripting Example


The following performs the same actions as the first ViewScript example
above, written in VBScript:
View.AppExec "Notepad.exe c:\Temp\readme.txt", 3
The following performs the same actions as the second ViewScript example
above, written in VBScript:
View.AppExec "cmd /c type c:\test.txt > \\5.6.7.8\HPLaserJet6P"

See Also
ActivateApp, AppHelp, AppShow, SendKeys, SendValue
View Scripting Functions Application Access

AppHelp
Launches the Microsoft WinHelp viewer with the specified help file (.HLP file).
WinHelp searches for the specific topic or string when help is started.
Supported by: Windows PC targets only

Active Scripting syntax


View.AppHelp strHelpFile [, strSearchKey]

ViewScript syntax
AppHelp strHelpFile [, strSearchKey]

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strHelpFile strHelpFile String expression specifying the full path
and file name of the help file. Use either a
literal string or a STRING variable.
strSearchKey strSearchKey (Optional) String expression indicating the
help topic or word to search for. Use either
a literal string or a STRING variable.

Comments
WinHelp is the legacy help file format, mostly used by Windows-based
machines before Windows 95. WinHelp files have a "*.HLP" extension. They
are sometimes accompanied by table of contents files with the same name
and a "*.CNT" extension.

ViewScript Example
The following ViewScript example loads the help file 'MyHelp' and search for
the topic 'Topic1':
AppHelp "C:\Program Files\MyApplication\MyHelp.hlp", "Topic1"

Active Scripting Example


This sample is the same as above, written in VBScript.
View.AppHelp "C:\Program Files\MyApplication\MyHelp.hlp", "Topic1"

See Also
ActivateApp, AppExec, AppShow, SendKeys, SendValue
View Scripting Functions Application Access

AppShow
Changes the display status of an application window. You can minimize,
maximize, hide, or display it normally.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.AppShow strAppTitleOrClassName, numShowMode [,
numSearchForClassFlag]

ViewScript syntax
AppShow strAppTitleOrClassName, numShowMode [,
numSearchForClassFlag]

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strAppTitleOrClassName strAppTitleOrClassName String expression indicating
the windows title or class
name. Use either a literal
string or a STRING variable.
numShowMode numShowMode Integer value indicating how
the application should be
displayed. Valid values are:
0: Hidden Window
1: Normal Window
2: Minimized Window
3: Maximized Window
4: Restore the window,
but don't activate it
(also see Comments
below)
5: Show Hidden
Window
6: Minimized and not
active
Note: If numShowMode is outside
the 0-6 range, it will default to 1
(Normal).
numSearchForClassFlag numSearchForClassFlag (Optional) If 1,
strAppTitleOrClassName
specifies a class name; if 0
(the default), it indicates a
title.

Return Value
This function returns 1 if the operation completed successfully, 0 otherwise.

Comments
Using a value of 4 for numShowMode tells Windows to restore the display of
the application window, but not activate it. However, if the user minimized
the window by clicking its button on the taskbar at the bottom of the desktop,
the application window will be restored and activated. This is a known
limitation of Windows.
Immediately after an application window opens (or after it switches modes),
you may need to pause your script to give time for the new window mode to
initialize. You can do so by using the SLEEP command. For example:
AppExec "Notepad.exe", 2
SLEEP 1
AppShow "Untitled - Notepad", 4
On some Windows 2000 systems, starting a window in one script and
activating with AppShow in another may confuse Windows as to the current
mode of the window. Specifically, using AppShow with a numShowMode
setting of 1 (Normal Window) may not function correctly. To work around this
issue, use AppShow with a numShowMode setting of 4 and add an additional
call to ActivateApp. For example:
'This is in Script 1
AppExec "Notepad.exe", 2

'This is in Script 2, called after Script 1


AppShow "Untitled - Notepad", 4
ActivateApp "Untitled - Notepad"
SendKeys "Hello, world{enter}"

ViewScript Example
The following ViewScript example hides the TrendX application.
HideTrendX := AppShow "TRENDX", 0, 1

Active Scripting Example


This sample is the same as above, written in VBScript.
HideTrendX.Value = View.AppShow ("TRENDX", 0, 1)

See Also
ActivateApp, AppExec, AppHelp, SendKeys, SendValue
View Scripting Functions Application Access

SendKeys
Sends keystrokes to the active application.
Note: SendKeys sends keystrokes to the active application. Use the ActivateApp script function to
activate an application.

Supported by: Windows PC targets only

Active Scripting syntax


View.SendKeys strKeyString

ViewScript syntax
SendKeys strKeyString

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strKeyString strKeyString String expression indicating the series of
keystrokes to send.

Return Value
None

Comments
Each key is represented by one or more characters. To specify a single
keyboard character, use the character itself. For example, to represent the
letter A, type "A" as the argument to the SendKeys command.
For more information on special keys and characters, see Special Keys and
Characters.
Note: Many applications do not process keystrokes unless they are fully displayed in foreground
mode. To work around this, include a short delay between activating an application and sending
keys to it. See the example below.

ViewScript Example
The following ViewScript example activates Windows Notepad and send keys
to it to write the text "Hello" and then an Enter.
Active := ActivateApp "Notepad", 1
If Active = 1
Sleep 1
SendKeys "Hello.{enter}"
Endif

Active Scripting Example


This sample is the same as above, written in VBScript.
Active.Value = View.ActivateApp ("Notepad", 1)
If Active.Value = 1 Then
View.SendKeys "Hello.{enter}"
End If

See Also
ActivateApp, AppExec, AppHelp, AppShow, SendValue
View Scripting Functions Application Access

SendValue
Sends a formatted value to the active application in the form of a sequence of
keystrokes.
Supported by: Windows PC targets only

Active Scripting syntax


View.SendValue strVarValueToSendName [, numDigits, numDecimals]

ViewScript syntax
SendValue varValueToSend [, numDigits, numDecimals]

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strVarValueToSendName varValueToSend The name of the Machine Edition
variable containing the value to
send.
numDigits numDigits (Optional) Integer. Specifies the
minimum field(digits) width. The
string sent will be at least the width
specified, and wider if necessary. If
the number has fewer characters
than the specified width, its padding
characters will be added from the
left.
numDecimals numDecimals (Optional) Integer. The number of
digits placed after the decimal point
in the string.

Return Value
None

Comments
When using this function in an Active Scripting language (such as VBScript),
names of all items and variables in parameters must be written as string
expressions. Also, strVarValueToSendName cannot refer to a variable that is
locally defined in VBScript with a DIM statement.

ViewScript Example
The following ViewScript example sends the value of the variable Sendout,
converted to at "string" of at least a 5-characters with two decimal points. If
the value of Sendout was 17.8, "17.80" would be sent to the active
application.
SendValue Sendout,5,2

Active Scripting Example


This sample is the same as above, written in VBScript.
View.SendValue Sendout.Name,5,2

See Also
ActivateApp, AppExec, AppHelp, AppShow, SendKeys
View Scripting Functions

CSV File script functions

CSV File functions let you open and retrieve data stored in CSV (Comma-
Separated Value) files from View scripts. For a description of how CSV files
work, see Using CSV files with View.
The following CSV File Functions are available:
Function Description
CSVCloseFile Closes an open CSV file, freeing up the memory used to
store it.
CSVGetNumFields Retrieves the number of fields in a single line or rows in an
open CSV file.
CSVGetNumLines Retrieves the number of lines in an open CSV file.
CSVGetValue Retrieves the value of a specific field in an open CSV file.
CSVOpenFile Opens a CSV file for use by other CSV functions.
Using CSV files with View

CSV file format

(Not supported by QuickPanel targets.)

CSV (Comma-Separated Value) files are data files whose individual fields are
separated with a specific character. Most often, this character is a comma (",") or a
TAB character. With CSV functions, your View scripts can access and use values stored

in a CSV file. This can be useful if you store recipe-like information in CSV files, or if
you want to read a user database to determine access privileges.
Typically, a script using CSV functions would do the following:

1. The script opens a CSV file with CSVOpenFile, acquiring a file handle and
copying the CSV file's data into the computer's memory.
2. The script determines the number of lines and fields in the CSV file with
CSVGetNumLines and CSVGetNumFields, respectively.
This step is only necessary if you're not sure how many lines or fields there are
in the CSV file, or if you want to make sure that the CSV file was read into
memory correctly.
3. The script copies data into relevant variables with CSVGetValue.
4. The script closes the CSV file with CSVCloseFile, releasing the memory used to
store the CSV file's data.

The only limit to the number of CSV files you can have open at a time is the amount
of memory on your computer. However, with several CSV files open at a time, this
can cause performance of the View Runtime to degrade. It's a good idea to close any
open CSV files when you're done with them—especially on target HMI units with
limited memory, like QuickPanel View/Control targets.
CSV files are typically stored on the HMI unit. If you do not specify a path name
when opening the CSV file (with CSVOpenFile), View Runtime looks for the file in the
downloaded project directory. You can include necessary CSV files as Supplemental
files to ensure that they get downloaded along with the rest of the project.
Alternatively, on QuickPanel View/Control targets, View Runtime
then looks in the root directory of the HMI unit's file system. Therefore, you may
wish to manually copy the CSV file to the root folder of the HMI unit, instead of
including it in the Supplemental Files folder. This saves wear and degradation of
Flash memory, since the CSV file will not be continually written to the unit during
every download operation.
For an example of a CSV file and a script that reads data from it, see Sample CSV
script.

CSV file format


CSV files are text-based database files, usually with a "CSV" file name extension.
Each record is stored on a single line. Each field in a single record is separated with a
special character called a delimiter. Typically, this delimiter is a comma (",") or a
TAB character. A standard carriage return indicates the end of a line.
In some cases, you may need to include the delimiter character within a field's
value. For example, a comma appears in the company name Smith, Smith, and
Sons. In this case, you will have to edit the file to use a different delimiter, such as
the TAB key.
The following lines comprise a sample CSV file. This is the same CSV file used by the
Sample CSV script.
ApplicationID,ProductID,DispenseLocation,DispenseVolume,DispenseMeasureType
1,044-6007,2,34,1
1,044-6008,2,35,2
This CSV file has three records or lines. Each line has five fields. Note that the first
line consists of a series of labels for each field. View Runtime doesn't distinguish
between these labels and the later numeric values; initially, it reads in all data as
strings. An individual field's value is automatically converted to a number (if
necessary) when copied to a variable with CSVGetValue.
Sample CSV script (ViewScript)

The following ViewScript example illustrates how to retrieve values from a CSV (Comma-
Separated Value) file. The sample script assumes a CSV file that looks something like the
following:
ApplicationID,ProductID,DispenseLocation,DispenseVolume,DispenseMeasureType
1,044-6007,2,34,1
1,044-6008,2,35,2
When the View runtime reads the CSV file into memory with CSVOpenFile, its data is
stored into a 3-line, 5-field table as follows:
Field number
1 2 3 4 5
1 ApplicationID ProductID DispenseLocation DispenseVolume DispenseMeasureType
Line
2 1 044-6007 2 34 1
Number
3 1 044-6008 2 35 2
Note that View Runtime reads the entire file into memory as a series of strings. Field 1 in
line 1 is a string containing "ApplicationID". Fields 1 in lines 2 and 3 are strings containing
"1". At this point, View runtime doesn't care what kind of data each field contains. Values
are only converted to non-string values when you call CSVGetValue on the open CSV
file—and even then only when you store the value in a non-string variable.
If you were to call CSVGetNumLines for this CSV file (retrieving the number of lines), it
would return 3. Similarly, if you were to call CSVGetNumFields (retrieving the number of
fields), it would return 5. Both lines and fields are numbered starting at 1.

ViewScript Example
This ViewScript sample extracts the DispenseVolume for the last line:
DECLARE _CSVFileHandle
DECLARE _Lines
DECLARE _Fields

' We assume that the CSV file 'testfile.csv'


' is stored in the root directory of drive C.
_CSVFileHandle := CSVOpenFile "c:\testfile.csv", ","
_Lines := CSVGetNumLines _CSVFileHandle
_Fields := CSVGetNumFields _CSVFileHandle

' We want to retrieve DispenseVolume for the last line


' and store it in the variable 'LastDispVolume'.
' We know DispenseVolume is in field 4. We can use
' _Lines to make sure we retrieve the DispenseVolume
' value for the last line.
CSVGetValue _CSVFileHandle, _Lines, 4, LastDispVolume
' It's always a good idea to close a CSV file when
' you're done with it.
CSVCloseFile _CSVFileHandle

Active Scripting Example


This sample is the same as above, written in VBScript.
Dim _CSVFileHandle, _Lines, _Fields
_CSVFileHandle = View.CSVOpenFile ("c:\testfile.csv", ",")
_Lines = View.CSVGetNumLines (_CSVFileHandle)
_Fields = View.CSVGetNumFields (_CSVFileHandle)

View.CSVGetValue _CSVFileHandle, _Lines, 4, LastDispVolume.Name


View.CSVCloseFile _CSVFileHandle
View Scripting Functions CSV File

CSVCloseFile
Closes a currently-open CSV (Comma-Separated Value) file, freeing the
memory used to store it.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.CSVCloseFile numFileHandle

ViewScript syntax
CSVCloseFile numFileHandle

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
numFileHandle numFileHandle The file handle for the open CSV file that
you want to close, as acquired from
CSVOpenFile.

Return Value
This function returns 1 if the CSV file was successfully closed, 0 otherwise.

Comments
For more information on CSV files and how they are laid out, see Using CSV
Files with View.

ViewScript Example
The following ViewScript example closes a CSV file, whose file handle was
stored in MyCSVFileHandle.
Tip: For a complete example of a CSV script, see Sample CSV script.
MyCloseFileStatus := CSVCloseFile MyCSVFileHandle

Active Scripting Example


This sample is the same as above, written in VBScript.
MyCloseFileStatus.Value = View.CSVCloseFile (MyCSVFileHandle.Value)

See Also
CSVOpenFile, CSVGetNumLines, CSVGetNumFields, CSVGetValue
View Scripting Functions CSV File

CSVGetNumFields
Retrieves the maximum number of fields per line in an open CSV (Comma-
Separated Value) file.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.CSVGetNumFields numFileHandle

ViewScript syntax
CSVGetNumFields numFileHandle

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
numFileHandle numFileHandle The file handle for the open CSV file, as
acquired from CSVOpenFile.

Return Value
This function returns the maximum number of fields in a line in the specified
CSV file as an integer (analog) value. If numFileHandle is not a valid file
handle for an open CSV file, or another error occurs, the function returns 0.

Comments
CSV files are essentially text database files. One "record" is stored on each
line, with each field in a record separated by a delimiter character (usually a
comma or TAB character). When CSVOpenFile is called, View Runtime attempts
to parse the file into a table. CSVGetNumFields returns the maximum number
of fields it found in a single line. This is the maximum value of the numField
parameter of CSVGetValue for that CSV file.
CSVGetNumFields can be useful if you're not sure how many fields there are
in a CSV file, or if you want to confirm that the file was correctly read into
memory.
For more information on CSV files and how they are laid out, see Using CSV
Files with View.
ViewScript Example
The following ViewScript example retrieves the number of fields per line in an
open CSV file whose file handle is stored in MyCSVFileHandle. This number is
stored in MyNumFields.
Tip: For a complete example of a CSV script, see Sample CSV script.
MyNumFields := CSVGetNumFields MyCSVFileHandle

Active Scripting Example


This sample is the same as above, written in VBScript.
MyNumFields.Value = View.CSVGetNumFields (MyCSVFileHandle.Value)

See Also
CSVOpenFile, CSVGetNumLines, CSVGetValue, CSVCloseFile
View Scripting Functions CSV File

CSVGetNumLines
Retrieves the number of lines found in an open CSV (Comma-Separated
Value) file.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.CSVGetNumLines numFileHandle

ViewScript syntax
CSVGetNumLines numFileHandle

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
numFileHandle numFileHandle The file handle for the open CSV file, as
acquired from CSVOpenFile.

Return Value
This function returns the number of lines in the specified CSV file as an
integer (analog) value. If numFileHandle is not a valid file handle for an open
CSV file, or another error occurs, the function returns 0.

Comments
CSV files are essentially text database files. One "record" is stored on each
line, with each field in a record separated by a delimiter character (usually a
comma or TAB character). When CSVOpenFile is called, View Runtime attempts
to parse the file into a table. CSVGetNumLines returns the number of lines
found in the CSV file. This is the maximum value of the numLine parameter
of CSVGetValue for that CSV file.
CSVGetNumLines can be useful if you're not sure how many lines there are in
a CSV file, or if you want to confirm that the file was correctly read into
memory.
For more information on CSV files and how they are laid out, see Using CSV
Files with View.
ViewScript Example
The following ViewScript example retrieves the number of lines in an open
CSV file whose file handle is stored in MyCSVFileHandle. This number is
stored in MyNumLines.
Tip: For a complete example of a CSV script, see Sample CSV script.
MyNumLines := CSVGetNumLines MyCSVFileHandle

Active Scripting Example


This sample is the same as above, written in VBScript.
MyNumLines.Value = View.CSVGetNumLines (MyCSVFileHandle.Value)

See Also
CSVOpenFile, CSVGetNumFields, CSVGetValue, CSVCloseFile
View Scripting Functions CSV File

CSVGetValue
Retrieves the value of a specific field in a specific line from an open CSV
(Comma-Separated Value) file, storing it in a variable.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.CSVGetValue numFileHandle, numLine, numField,
strVarDataBufferName

ViewScript syntax
CSVGetValue numFileHandle, numLine, numField, varDataBuffer

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
numFileHandle numFileHandle The file handle for the open CSV file, as
acquired from CSVOpenFile.
numLine numLine Integer. The line with the field whose
value you want to get. This can be from
1 through the number of lines in the
CSV file.
Tip: You can find out how many lines there are for
the CSV file with CSVGetNumLines.
numField numField Integer. The field whose value you
want to get. This can be from 1 through
the maximum number of fields in the
CSV file.
Tip: You can find out the maximum number of
fields in a line for the CSV file with
CSVGetNumFields.
strVarDataBufferName varDataBuffer The name of the Machine Edition
variable in which the value is to be
stored. This can be any integer (INT,
DINT, UINT, BYTE, WORD, DWORD),
real (REAL, LREAL), boolean (BOOL), or
string (STRING) variable. See
Comments below for a description of
how CSVGetValue converts the value
into an appropriate data type.

Return Value
This function returns 1 if the value was retrieved correctly; 0 otherwise.

Comments
CSV files are essentially text database files. One "record" is stored on each
line, with each field in a record separated by a specific character (usually a
comma or TAB character). CSVOpenFile reads the contents of a CSV file into
memory, storing it as a table of strings. CSVGetValue retrieves the value of a
specific field on a specific line into a variable.
Values of fields in an open CSV file are stored in memory as strings.
CSVGetValue automatically converts this value to the data type of the
variable specified in varDataBuffer. The conversion process works as follows:

● Integer values (INT, DINT, UINT, BYTE, WORD, DWORD variables):


The function reads up to the first non-numerical digit character. A minus
sign at the beginning indicates a negative value. For example,
"23skidoo" is converted to 23; and "-14.5" is converted to -14. If the
field value begins with any other character, the function sets the
variable to 0.
● Real values (REAL, LREAL variables): The function reads up to the first
non-digit character. A minus sign at the beginning ("-") indicates a
negative value. A single period (".") is allowed and indicates the decimal
place. For example, "145.23.56.133" is converted to 145.23; "23skidoo"
is converted to 23; and "-14.5" is converted to -14.5. If the field value
begins with any other character, the function sets the variable to 0.
Tip: Scientific notation is also supported. For example, "3.5e10" would be converted to
35,000,000,000
● Boolean values (BOOL variables): The function first tries to read the
field value as an integer. If the field value evaluates as an integer value
of 0, the BOOL variable is set to False (off). If the value evaluates as a
non-zero integer value, the BOOL variable is set to True (on). For
example, "0", "Walter", and "-.45" evaluate to False; whereas "1",
"23skidoo", and "-14.5" evaluate to True.
● String values (STRING variables): The field's value is copied to the
STRING variable unchanged. However, any characters beyond the Max
Length of the STRING variable are truncated.

Note: If the data type of varDataBuffer is not one of those listed above, the field value is not
retrieved and CSVGetValue returns 0.

When using this function in an Active Scripting language (such as VBScript),


names of all items and variables in parameters must be written as string
expressions. Also, strVarDataBufferName cannot refer to a variable that is
locally defined in VBScript with a DIM statement.
For more information on CSV files and how they are laid out, see Using CSV
Files with View.

ViewScript Example
The following ViewScript example copies the value of the first field in the third
line of an open CSV file (with a file handle stored in MyCSVFileHandle) into a
variable MyInteger.
Tip: For an complete example of a CSV script, see Sample CSV script.
MyRetrieveStatus := CSVGetValue MyCSVFileHandle, 3, 1, MyInteger

Active Scripting Example


This sample is the same as above, written in VBScript.
MyRetrieveStatus.Value = View.CSVGetValue (MyCSVFileHandle.Value, 3,
1, MyInteger.Name)

See Also
CSVOpenFile, CSVGetNumLines, CSVGetNumFields, CSVCloseFile
View Scripting Functions CSV File

CSVOpenFile
Opens a CSV (Comma-Separated Value) file and reads its contents into
memory, returning a file handle for use by other CSV functions.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.CSVOpenFile strFileName [, strDelimiter]

ViewScript syntax
CSVOpenFile strFileName [, strDelimiter]

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strFileName strFileName String containing the full file name of the
CSV file you want to read, including drive
and path information and the .CSV
extension.
Note: If no drive or path information is included in
strFileName, View Runtime looks for the file in the
downloaded project directory. On
QuickPanel View/Control targets, if it is not found, it
then looks in the root folder of the file system.

strDelimiter strDelimiter (Optional) A single character to use as a


separator between fields on a single line.
This can be any printable character (such
as a comma "," or bar "|") or "\t", which
indicates the TAB character. If strDelimiter is
not specified, CSVOpenFile assumes it to
be a comma (",").

Return Value
This function returns an integer (analog) value as follows:
0: The CSV file could not be opened, or an error occurred when reading
it into memory.
> 0: The CSV file was opened successfully. The returned value is a "file
handle" to be used by other CSV files.

Comments
CSV files are essentially text database files. One "record" is stored on each
line, with each field in a record separated by a specific character (usually a
comma or TAB character). CSVOpenFile reads the contents of a CSV file into
memory, storing it as a table of strings. You can then copy the value of a
specific cell in the table into a variable with CSVGetValue.
You can have as many CSV files open at once as you'd like. You are only
limited by the target computer's memory. However, the more CSV files you
have open, the more performance will degrade. We highly recommend you
close each CSV file when you're done with it with CSVCloseFile—especially on
QuickPanel View/Control targets.
If the CSV file is to be stored on the HMI unit itself, you can store it in the
downloaded project directory or (on QuickPanel View/Control targets), on
the root directory of the target's file system.

● Storing it in the downloaded project directory lets you easily download


or update the CSV file by simply adding it to the project as a
Supplemental File. The disadvantage is that the CSV file will be
rewritten to the HMI unit every time the project is downloaded.
● (QuickPanel View/Control targets only.) storing it in the root directory
requires you to manually copy the file to the unit's file system. This
requires a bit more effort, but saves wear on the unit's file system
and (assuming you do not also include it in the project's
Supplemental Files folder) shortens the subsequent download times.
This can be very important on QuickPanel View/Control
targets, which use Flash memory.
Note: If a copy exists in both the project directory and the file system's root directory, the
copy in the project directory will be used.

When creating the table, CSVOpenFile does its best to figure out how many
fields there are in each line. You can find out the number of fields and lines it
found with CSVGetNumFields and CSVGetNumLines, respectively.
For more information on CSV files and how they are laid out, see Using CSV
Files with View.

ViewScript Example
The following ViewScript example reads the CSV file 'MyData.CSV' into
memory. It is assumed that this file was added to the project as a
supplemental file, so no drive or path information is needed. The delimiter
character is a comma (","). The file handle is stored in MyCSVFileHandle.
Tip: For a complete example of a CSV script, see Sample CSV script.
MyCSVFileHandle := CSVOpenFile "mydata.csv", ","

Active Scripting Example


This sample is the same as above, written in VBScript.
MyCSVFileHandle.Value = View.CSVOpenFile ("mydata.csv", ",")

See Also
CSVGetNumLines, CSVGetNumFields, CSVGetValue, CSVCloseFile
View Scripting Functions

File Management script functions

New file handling functions allow you to copy, move, rename, and delete files
using View scripts. This is useful for automatic file backup of log files and
distribution of report files.
Advanced features include full wildcard (* and ?) support. For risk-free
testing of the file handling functions, the FileSetDemoMode script disables the
actual file changes and prompts you to change the files and how you want
them changed.
This section covers the following file management functions:
Function Description
FileCopy Copies one or more files to another location.
FileMove Moves one or more files from one directory to another.
FileRename Changes the name of a file or directory.
FileDelete Erases one file, a group of files, or a directory.
FileSetDemoMode File commands are simulated in a dialog box, but no disk
activity occurs.
HttpCopy Copies a file from the local computer to an Internet server,
or vice versa.
HttpDelete Deletes a file from an Internet server.
View Scripting Functions File Management

FileCopy
Copies one or more files to another location and overwrite any existing
destination files.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.FileCopy strSource, strDestination [, numFailIfExists]

ViewScript syntax
FileCopy strSource, strDestination [, numFailIfExists]

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strSource strSource String expression indicating the path to the
file or folder to be copied. Use either a
literal string or a STRING variable.
strDestination strDestination String expression indicating the path to the
file or folder to copy the source file or
folder into. Use either a literal string or a
STRING variable.
numFailIfExists numFailIfExists (Optional) Indicates what action to take if
the strDestination files already exist. If 0
(the default), existing files will be
overwritten. If 1, existing files will be left
alone.

Return Value
This function returns 1 if the operation completed successfully, 0 otherwise.

Comments
This function supports wildcards.

ViewScript Example
The following ViewScript example copies all .ini extension files in
c:\ViewRuntime\project to the same directory while changing the extensions.
Error := FileCopy "c:\ViewRuntime\project\*.ini",
"c:\ViewRuntime\project\*.bak"
If Error = 0
Message "Error copying files"
Endif
Note: If a path is not specified, the current working directory is used.

Active Scripting Example


This sample is the same as above, written in VBScript.
Error.Value = View.FileCopy ("c:\ViewRuntime\project\*.ini",
"c:\ViewRuntime\project\*.bak")
If Error.Value = 0 Then
View.Message "Error copying files"
End If

See Also
FileMove, FileRename, FileDelete, FileSetDemoMode
View Scripting Functions File Management

FileDelete
Erases a file or a group of files.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.FileDelete strFileName

ViewScript syntax
FileDelete strFileName

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strFileName strFileName String expression indicating the file(s) to
be deleted. Use either a literal string or a
STRING variable.

Return Value
This function returns 1 if the operation completed successfully, 0 otherwise.

Comments
This function supports wildcard functions.

ViewScript Example
The following ViewScript example deletes all .ini extension files in
c:\ViewRuntime\project.
Error := FileDelete "c:\ViewRuntime\project\*.ini"
Note: If a path is not specified, the return value will be 0.

Active Scripting Example


This sample is the same as above, written in VBScript.
Error.Value = View.FileDelete ("c:\ViewRuntime\project\*.ini")
See Also
FileSetDemoMode, FileCopy, FileMove, FileRename
View Scripting Functions File Management

FileMove
Moves a file or files from one directory to another.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.FileMove strSource, strDestination [, numFailIfExists]

ViewScript syntax
FileMove strSource, strDestination [, numFailIfExists]

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strSource strSource String expression indicating the path and
file name of the file(s) to be moved. Use
either a literal string or a STRING variable.
strDestination strDestination String expression indicating the path and
file name of the file(s) to copy the source
file into. Use either a literal string or a
STRING variable.
numFailIfExists numFailIfExists (Optional) Indicates the action to take if
the strDestination files already exist. If 0,
existing files are overwritten. If 1 (the
default), existing files are left alone.

Return Value
This function returns 1 if the operation completed successfully, 0 otherwise.

Comments
This function supports wildcard functions.

ViewScript Example
The following ViewScript example copies all .ini extension files in
c:\ViewRuntime\project to the same directory while changing the extensions.
Error := FileMove "c:\ViewRuntime\project\*.ini",
"c:\ViewRuntime\project\*.bak"
If Error = 0
Message "Error moving files"
Endif
Note: If a path is not specified, the current working directory is used.

Active Scripting Example


This sample is the same as above, written in VBScript.
Error.Value = View.FileMove ("c:\ViewRuntime\project\*.ini",
"c:\ViewRuntime\project\*.bak")
If Error.Value = 0 Then
View.Message "Error moving files"
End If

See Also
FileCopy, FileDelete, FileRename, FileSetDemoMode
View Scripting Functions File Management

FileRename
Use FileRename to change the name of a file.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.FileRename strOldName, strNewName

ViewScript syntax
FileRename strOldName, strNewName

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strOldName strOldName The original path and file name(s). Use
either a literal string or a STRING variable.
strNewName strNewName The new path and file name(s). Use either
a literal string or a STRING variable.

Return Value
1: Success
0: Error

Comments
This function supports wildcard functions.

ViewScript Example
The following ViewScript example changes the name of 'file.txt' to
'newfile.txt' in c:\ViewRuntime\project:
MyNameChgStatus := FileRename "c:\ViewRuntime\project\file.txt",
"c:\ViewRuntime\project\newfile.txt"

Active Scripting Example


This sample is the same as above, written in VBScript.
MyNameChgStatus.Value = View.FileRename
("c:\ViewRuntime\project\file.txt",
"c:\ViewRuntime\project\newfile.txt")

See Also
FileCopy, FileMove, FileDelete, FileSetDemoMode
View Scripting Functions File Management

FileSetDemoMode
Sets file management functions to "demo mode", preventing damage to files
in your system while testing HMI applications.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.FileSetDemoMode numNewMode

ViewScript syntax
FileSetDemoMode numNewMode

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
numNewMode numNewMode Specify 1 for demo mode and 0 for real-
time.

Return Value
None

Comments
While in demo mode, calls to file management functions do not perform the
appropriate operations. Instead, a dialog box appears describing the
operation that would have taken place. This lets you test and debug scripts
without affecting important files on the target.
Demo mode works with all file management functions except for HttpCopy
and HttpDelete.
Tip: To debug a specific section of script, enable demo mode before that section, and disable it
afterwards.
Warning: When viewing QuickPanel View/Control HMI graphical panels remotely over the web
(see Remote Viewing of View Runtime), any dialog boxes that are opened because of actions
performed remotely on the HMI will not be closed on the QuickPanel View/Control display. This
will eventually cause the HMI application to fail. If you want to use a script function that opens a
dialog box on a QuickPanel View/Control target, it is highly recommended that you do not allow
users to operate the HMI remotely.
ViewScript Examples
Example 1: Enable demo mode in ViewScript:
FileSetDemoMode 1

Example 2: Disable demo mode:


FileSetDemoMode 0

Active Scripting Examples


These samples are the same as above, written in VBScript.
Example 1: Enable demo mode in ViewScript:
View.FileSetDemoMode 1

Example 2: Disable demo mode:


View.FileSetDemoMode 0

See Also
FileCopy, FileMove, FileRename, FileDelete
View Scripting Functions File Management

HttpCopy
Uses the HTTP protocol to copy a local file to an Internet Server, or vice
versa.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.HttpCopy strSource, strDestination, strVarResultName

ViewScript syntax
HttpCopy strSource, strDestination, varResult

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strSource strSource String expression indicating the full HTTP
URL or the full drive, path, and file name
of the file to be transferred. This can be a
literal string or a STRING variable.
strDestination strDestination String expression indicating the full HTTP
URL or the full drive, path, and file name
of the destination into which to copy the
file. Use either a literal string or a STRING
variable.
strVarResultName varResult An integer Machine Edition variable (INT,
DINT, UINT, WORD, DWORD) in which the
results of the HTTP operation will be
stored. While the HTTP command is being
performed, the value of the variable is 1. If
the function completes successfully, the
variable's value is set to 200 (or 201). If
an error occurs, the variable's value is set
to an error code. For a complete list of
return codes, see HttpCopy and HttpDelete
Return Codes.
Return Values
The function does not have a return code as such. However, the ongoing
results of the HTTP operation are stored in the variable indicated by the
varResult or strVarResultName parameter. For a complete list of possible
values for the varResult or strVarResultName variable, see HttpCopy and
HttpDelete return codes.

Comments
Of strSource and strDestination, one must refer to a local file and one to a file
on an Internet Server. The local file should include the full drive, path, and
file name, as in "C:\Program Files\MyProgram\readme.txt". The Server file
name should use the HTTP syntax, as in
"HTTP://MyServer/MyFiles/readme.txt" or "//MyServer/MyFiles/readme.txt".
Warning: If a writeable (that is, not read-only) file already exists with the file name or URL
specified by strDestination, that file will be overwritten.

For file transfers from an Internet server to the local computer, HttpCopy
uses the HTTP Get command. For file transfers in the other direction, it uses
the HTTP Put command.
If HttpCopy fails, check the security settings of your web server to make sure
the HTTP operation is allowed. Firewalls, proxy servers, and other security
arrangements may interfere with HTTP Put operations.
If you want to copy files between directories on the local computer, use
FileCopy.
Note: You cannot use Windows/DOS wildcard characters ("*" or "?") with HttpCopy. You also
cannot refer to the upper directory with the "../" character sequence.

When using this function in an Active Scripting language (such as VBScript),


names of all items and variables in parameters must be written as string
expressions. Also, strVarResultName cannot refer to a variable that is locally
defined in VBScript with a DIM statement.

ViewScript Example
The following ViewScript example copies the MyFile.txt folder stored in the
"data" directory of drive C: to the "media" subdirectory on the Internet server
'MyServer'.
HttpCopy "c:\data\MyFile.txt", "http://MyServer/media/MyFile.txt",
MyResults
Active Scripting Example
This sample is the same as above, written in VBScript.
View.HttpCopy "c:\data\MyFile.txt",
"http://MyServer/media/MyFile.txt", MyResults.Name

See Also
HttpDelete, FileCopy
View Scripting Functions File Management

HttpDelete
Uses the HTTP protocol to delete a file from an Internet Server.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.HttpDelete strFile, strVarResultName

ViewScript syntax
HttpDelete strFile, varResult

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strFile strFile String expression indicating the full HTTP
URL of the file to be deleted. This can be a
literal string or a STRING variable. The
URL must include the "HTTP://" or "//"
prefix.
strVarResultName varResult An integer Machine Edition variable (INT,
DINT, UINT, WORD, DWORD) in which the
results of the HTTP operation will be
stored. While the HTTP command is being
performed, the value of the variable is 1. If
the function completes successfully, the
variable's value is set to 2. If an error
occurs, the variable's value is set to an
error code. For a complete list of return
codes, see HttpCopy and HttpDelete
Return Codes.

Return Values
The function does not have a return code as such. However, the ongoing
results of the HTTP operation are stored in the variable indicated by the
varResult or strVarResultName parameter. For a complete list of possible
values for the varResult or strVarResultName variable, see HttpCopy and
HttpDelete return codes.

Comments
This function uses the HTTP Delete command to perform the operation.
If the file is marked as read-only, it will not be deleted.
If HttpDelete fails, check the security settings of your web server to make
sure the HTTP operation is allowed. Firewalls, proxy servers, and other
security arrangements may interfere with HTTP Delete operations.
If you want to delete files on the local computer, use FileDelete.
Note: You cannot use Windows/DOS wildcard characters ("*" or "?") with HttpDelete. You also
cannot refer to the upper directory with the "../" character sequence.

When using this function in an Active Scripting language (such as VBScript),


names of all items and variables in parameters must be written as string
expressions. Also, strVarResultName cannot refer to a variable that is locally
defined in VBScript with a DIM statement.

ViewScript Example
The following ViewScript example deletes the MyFile.txt folder stored in the
"media" subdirectory on the Internet server 'MyServer'.
HttpDelete "http://MyServer/media/MyFile.txt", MyResults

Active Scripting Example


This sample is the same as above, written in VBScript.
View.HttpDelete "http://MyServer/media/MyFile.txt", MyResults.Name

See Also
HttpCopy, FileDelete
View Scripting Functions File Management

HttpCopy and HttpDelete return codes


Standard status codes | Server status codes

The following tables indicate the possible "return codes" for the HttpCopy and
HttpDelete script functions. Unlike other functions, the return codes for these
operations are stored in the variable indicated by the strReturn parameter.
If the local computer is able to establish a connection with the Internet
server, the return code will (eventually) contain the error or status code
returned by the server. These codes all have values of 100 or greater.
Otherwise, it returns one of the standard error codes below.
Tip: If HttpCopy or HttpDelete fails, check the security settings of your web server to make sure the
operation is allowed. Firewalls and proxy server settings can filter HTTP "delete" and "put"
operations.

Standard status codes


Return Explanation
code
-1 Too many requests: The server is receiving too many data requests
from clients. This may or may not be a temporary condition.
0 Completed successfully: The HTTP operation completed
successfully. (Also see Server status codes below.)
1 In progress: The HTTP operation is still in progress. The amount of
time it takes for an HTTP copy or delete operation can vary
depending on how far away the Server is, and on the amount of
Internet traffic between the local computer and the Server. As long
as the ultimate result of the operation is unknown, the return code is
set to 1.
3 Invalid URL: The URL of the Internet Server is invalid. Check to see
if the HTTP syntax is correct—that is, that the URL begins with
"HTTP://" and that subdirectories are indicated with a regular slash
character ("/").
4 Command Line is not correct: The syntax for the command could
not be understood.
5 URL not found: (HttpDelete only) When using HttpDelete, the
strSource must use the HTTP syntax to refer to a location on an
Internet Server.
6 Internet open failed: The local computer could not connect to the
Internet at all.
7 HTTP open request failed: The HTTP Open request could not be
completed.
8 Failed to create Internet session: The indicated Internet Server
was found, but the local computer failed to initiate a session. This can
occur (for example) if security restrictions are present on the Server.
9 Create file failed: (HttpCopy only.) The destination file could not be
created.
10 Error sending request: An error occurred while sending the HTTP
command.
11 Error with local file: (HttpCopy only.) An error occurred when
trying to access the local file. The path and file name may be
incorrect, or the file's read-only flag may be set.
12 Server not responding: The local computer can see the Internet,
but could not connect to it.
13 Identical parameter types: (HttpCopy only.) When using
HttpCopy, one of strSource and strDestination must refer to a local
file, and the other must use the HTTP syntax to refer to a location on
an Internet Server. Both cannot be of the same type.
14 Remote file does not exist: The file at the specified HTTP address
either does not exist or is a 0-byte file.
15 File not found: The Source file could not be found.
16 Error writing file: The Source file could not be found.

Server status codes


The following table lists the most common status codes that might be
returned by the server. These are in the 400-level (Client) and 500-level
(Server) areas.
Return code Name Explanation
200 OK The command completed
successfully.
201 Created The command completed
successfully, and a new URI has
been created.
202 Accepted The server has accepted the
command, but hasn't finished
processing it yet.
400 Bad Request The server did not understand
the command.
401 Unauthorized The command requires user
authentication by the client.
402 Payments Required The command requires some sort
of payment bd the client.
403 Forbidden The user (who has been
authenticated) does not have
permission to access the
indicated file.
404 Not Found The specified file could not be
found.
405 Method Not Allowed The method specified by the
command is not supported by
the server.
406 None Acceptable The file exists, but it may not
have the content type expected
by the client.
407 Proxy Authentication Required The proxy server must
authenticate the client before the
command can be processed.
408 Request Timeout The client timed out on the
command.
409 Conflict A resource conflict occurred.
410 Gone The file is no longer available.
411 Length Required The server expects the command
to have a content-length header.
413 Cannot process request The server is refusing to process
the command because the
request entity is larger than the
server is willing or able to
process. A possible reason could
be because the disk drive is full.
500 Internal Server Error An undeterminable error
occurred on the server.
501 Not Implemented The command is unavailable on
the server.
502 Bad Gateway The upstream server could not
be accessed by the gateway.
503 Service Unavailable Currently, the server could not
process the command.
504 Gateway Timeout The gateway timed out while
waiting for a response from the
upstream server.
View Scripting Functions

Initialization (INI) File script functions

Initialization (INI) file management functions let you read and write strings or
numbers to and from INI files. INI files store information in a text format for
Windows applications and are defined by the file extension .INI.
Note: These functions are supported only on Windows PC.

The following INI Management Functions are available:


Function Description
IniForceIniPath Sets the path to the INI files used with the following INI
management functions.
IniReadNumber Retrieves a number value stored in an INI file.
IniReadString Retrieves a string stored in an INI file.
IniWriteNumber Writes a number value to an INI file.
IniWriteString Writes a string to an INI file.
View Scripting Functions Initialization (INI) Files

IniForceIniPath
Sets the default path for the file in the strFileName parameter in
IniReadNumber, IniWriteNumber, IniReadString, and IniWriteString functions.
If you do not set a default path with IniForceIniPath, the default path name
for INI-related functions is "C:\WINNT". This applies to IniReadNumber,
IniWriteNumber, IniReadString, and IniWriteString.
Supported by: Windows PC targets only

Active Scripting syntax


View.IniForceIniPath strPathName

ViewScript syntax
IniForceIniPath strPathName

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strPathName strPathName String expression indicating the path to the
folder you want the strPathName
parameters in the other INI functions to
use as the default path.

Return Value
None

Comment
This function is not currently available on QuickPanel View/Control units.

ViewScript Example
The following ViewScript example sets the folder path to d:\apps.
IniForceIniPath "d:\apps"

Active Scripting Example


This sample is the same as above, written in VBScript.
View.IniForceIniPath "d:\apps"

See Also
IniReadNumber, IniReadString, IniWriteNumber, IniWriteString
View Scripting Functions Initialization (INI) Files

IniReadNumber
Retrieves a numeric value stored in an INI file.
Supported by: Windows PC targets only

Active Scripting syntax


View.IniReadNumber strFileName, strSectionName, strKeyName, numDefault

ViewScript syntax
IniReadNumber strFileName, strSectionName, strKeyName, numDefault

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strFileName strFileName String expression indicating the INI file from
which you want information.
strSectionName strSectionName String expression indicating the name of the
section from which you want to read data.
strKeyName strKeyName String expression indicating the name of the
key in the specified section.
numDefault numDefault The integer value to be returned if the section,
key, or file doesn't exist.

Return Value
The value retrieved from the .INI file.
Comment
The default path name for INI-related functions is "C:\WINNT". This applies to
IniReadNumber, IniWriteNumber, IniReadString, and IniWriteString. The script looks
in this directory for the specified INI file. You can change the default INI file path
name with IniForceIniPath.
This function is not currently available on QuickPanel View/Control units.
When using this function in an Active Scripting language (such as VBScript), names
of all items and variables in parameters must be written as string expressions.
Data in an .INI file is stored as follows:
[strSectionName]
strKeyName=value
ViewScript Example
In the following ViewScript example, the file applicat.ini contains the following two
lines:
[Shift]
Count=53

When the following function is executed, the variable ShiftCount gets the value 53.
ShiftCount := IniReadNumber "Applicat.ini", "Shift", "Count", 0

If the section Shift or the key Count doesn't exist, a value of zero is returned to
ShiftCount.

Active Scripting Example


This sample is the same as above, written in VBScript.
ShiftCount.Value = View.IniReadNumber ("Applicat.ini", "Shift", "Count", 0)

See Also
IniForceIniPath, IniReadString, IniWriteNumber, IniWriteString
View Scripting Functions Initialization (INI) Files

IniReadString
Retrieves a string value stored in an INI file.
Supported by: Windows PC targets only

Active Scripting syntax


View.IniReadString strFileName, strSectionName, strKeyName, strVarStringName,
strDefault

ViewScript syntax
IniReadString strFileName, strSectionName, strKeyName, strVarString, strDefault

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strFileName strFileName String expression indicating the INI file you want
information from.
strSectionName strSectionName String expression indicating the name of the
section from which you want to read data.
strKeyName strKeyName String expression indicating the name of the key
in the specified section.
strVarStringName strVarString String expression indicating the Machine Edition
STRING variable in which the value should be
stored.
strDefault strDefault String expression indicating the string to be
stored in the strVarString variable if the section,
key, or file doesn't exist.

Return Value
None

Comments
The maximum string length that can be returned from this function is 255 characters.
When using this function in an Active Scripting language, strVarStringName cannot refer
to the name of a variable that is locally defined in VBScript with a DIM statement.
The default path name for INI-related functions is "C:\WINNT". This applies to
IniReadNumber, IniWriteNumber, IniReadString, and IniWriteString. The script looks in
this directory for the specified INI file. You can change the default INI file path name
with IniForceIniPath.
Data in an .INI file is stored as follows:
[strSectionName]
strKeyName=value

ViewScript Example
In the following ViewScript example, the file applicat.ini contains the following two lines:
[Shift]
Operator=James
When the following function is executed, the variable 'ShiftOper' gets the string
"James".
IniReadString "Applicat.ini", "Shift", "Operator", ShiftOper, "None"
If the section Shift and key Count don't exist, the string None is returned to the
ShiftOper variable.

Active Scripting Example


This sample is the same as above, written in VBScript.
View.IniReadString "Applicat.ini", "Shift", "Operator", ShiftOper.Name, "None"

See Also
IniForceIniPath, IniReadNumber, IniWriteNumber, IniWriteString
View Scripting Functions Initialization (INI) Files

IniWriteNumber
Stores a numeric value in an INI file.
Supported by: Windows PC targets only

Active Scripting syntax


View.IniWriteNumber strFileName, strSectionName, strKeyName,
numValue

ViewScript syntax
IniWriteNumber strFileName, strSectionName, strKeyName, numValue

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strFileName strFileName String expression indicating the INI file
where you want information stored.
strSectionName strSectionName String expression indicating the name of
the section in which you want to store
information. The section is created if the
section specified doesn't exist.
strKeyName strKeyName String expression indicating the name of
the key in the specified section. The key is
created if the key specified doesn't exist.
numValue numValue The numerical value you want to store in
the specified key.

Return Value
None

Comments
If the section and key already exist in the .INI file, the value overwrites the
previously stored data.
The default path name for INI-related functions is "C:\WINNT". This applies
to IniReadNumber, IniWriteNumber, IniReadString, and IniWriteString. The
script looks in this directory for the specified INI file. You can change the
default INI file path name with IniForceIniPath.
Data in an .INI file is stored as follows:
[strSectionName]
strKeyName=numValue

ViewScript Example
In the following ViewScript example, the value 53 is stored in the key Count
under the section Shift in the file applicat.ini.
IniWriteNumber "Applicat.ini", "Shift", "Count", 53
The result would be the following lines in the applicat.ini file:
[Shift]
Count=53

Active Scripting Example


This sample is the same as above, written in VBScript.
View.IniWriteNumber "Applicat.ini", "Shift", "Count", 53

See Also
IniForceIniPath, IniReadNumber, IniReadString, IniWriteString
View Scripting Functions Initialization (INI) Files

IniWriteString
Stores a string value in an INI file.
Supported by: Windows PC targets only

Active Scripting syntax


View.IniWriteString strFileName, strSectionName, strKeyName, strString

ViewScript syntax
IniWriteString strFileName, strSectionName, strKeyName, strString

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strFileName strFileName String expression indicating the INI file
where you want information stored.
strSectionName strSectionName String expression indicating the name of
the section in which you want to store
information. The section is created if the
section specified doesn't exist.
strKeyName strKeyName String expression indicating the name of
the key in the specified section. The key is
created if it doesn't exist.
strString strString The string you want to store in the
specified key. Use either a literal string or
a STRING variable.

Return Value
None

Comments
If the section and key already exist in the .INI file, the string overwrites the
previously stored data.
The default path name for INI-related functions is "C:\WINNT". This applies
to IniReadNumber, IniWriteNumber, IniReadString, and IniWriteString. The
script looks in this directory for the specified INI file. You can change the
default INI file path name with IniForceIniPath.
Data in an .INI file is stored as follows:
[strSectionName]
strKeyName=numValue

ViewScript Example
In the following ViewScript example, the string James is stored in the key
Operator under the section Shift in the file applicat.ini.
IniWriteString "Applicat.ini", "Shift", "Operator", "James"
The result would be the following lines in the applicat.ini file:
[Shift]
Operator=James

Active Scripting Example


This sample is the same as above, written in VBScript.
View.IniWriteString "Applicat.ini", "Shift", "Operator", "James"

See Also
IniForceIniPath, IniReadNumber, IniWriteNumber, IniReadString
View Scripting Functions

List and Combo Box Script Functions

List and Combo Box script functions are used to add, edit, and manipulate
List Box and Combo Box entries. For examples of list and combo box
configuration, see Working With List Boxes and Working With Combo Boxes.

Function Description
lbAddString Adds a string to a list or combo box.
lbDeleteString Deletes a string from a list or combo box.
lbDeleteStringAtIndex Deletes a string at a specific zero-based index from a
list or combo box.
lbEmpty Removes the contents of a list or combo box.
lbFillWithDirectory Adds a list of filenames to a list or combo box.
lbFindString Finds the first string in a list or combo box that
contains the specified prefix.
lbFindStringExact Finds a string in a list or combo box.
lbGetCount Retrieves the number of entries in a list or combo box.
lbGetCurSel Returns the zero-based index value of the currently
selected entry, if any, in a list or combo box.
lbGetItemData Returns the 32-bit value (cookie) associated with a list
or combo box entry.
lbGetSelString Searches for the selected string in a list or combo box
and copies it into a variable.
lbGetString Searches for a string at a specific zero-based index in a
list or combo box and copies the string into a variable.
lbInsertString Inserts a string at a specific zero-based index into a list
or combo box. Adds a string to a list or combo box.
lbSelectString Searches for a string in a list or combo box, and if a
matching entry is found, selects the entry.
lbSetCurSel Finds a string at a specific zero-based index and
changes it to the current selection.
lbSetItemData Sets a 32-bit value (cookie) associated with a list or
combo box entry.
View Scripting Functions List and Combo Box

lbAddString
Adds a string to a list or combo box. By default, the string is added to the
end of the list or combo box. To sort strings alphabetically, set the box's
Sorted property to True.
Tip: To insert a string at a specific location within the list, call the lbInsertString script function.

Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.lbAddString strListBoxWinName, strNewString

ViewScript syntax
lbAddString lbWinName, strNewString

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strListBoxWinName lbWinName The name of the list or combo box
window.
strNewString strNewString String expression indicating the name of
the string you want added. You can use
either a literal string or a STRING
variable.
Note: You cannot add an empty string to a list box or combo box.

Comments
You can define tab stops within a list box string by inserting the tab
character. The tab character is defined in the Inspector on the list box, and
defaults to '~'. For example, "Monday~Tuesday~Friday" would result in three
columns, each ~ replaced by the values, in pixels, defined by the Tab Stops
property. When manipulating this string, the tab stops must be included.
When using this function in an Active Scripting language (such as VBScript),
names of all items and variables in parameters must be written as string
expressions.
Return Value
If successful, this function returns the zero-based index value of the string in
the list or combo box.
If lbWinName could not be found or strNewString is invalid, the function
returns -1.
If the list box or combo box already has the maximum number of entries, the
function returns -2.

ViewScript Examples
Example 1: The following ViewScript example adds the directions "North",
"East", "South", and "West" to the combo box "MyComboBox".
lbAddString MyComboBox, "North"
lbAddString MyComboBox, "East"
lbAddString MyComboBox, "South"
lbAddString MyComboBox, "West"

Example 2: The following ViewScript example adds "Recipe1" to the


"RecipeList" list box and displays an error message if the procedure is
unsuccessful. "RetVal" is a variable being used to store the return value.
RetVal := lbAddString RecipeList, "Recipe1"
IF retVal = -1
Message "Unable to add item."
ENDIF

Active Scripting Examples


Example 1: The following VBScript example adds the directions "North",
"East", "South", and "West" to the combo box "MyComboBox".
View.lbAddString "MyComboBox", "North"
View.lbAddString "MyComboBox", "East"
View.lbAddString "MyComboBox", "South"
View.lbAddString "MyComboBox", "West"
Example 2: The following VBScript example adds "Recipe1" to the
"RecipeList" list box and displays an error message if the procedure is
unsuccessful. "RetVal" is a variable being used to store the return value.
RetVal.Value = View.lbAddString ("RecipeList", "Recipe1")
If retVal.Value = -1 Then
View.Message "Unable to add item."
End If
See Also
lbDeleteString, lbFillWithDirectory, Working With List Boxes, Working With
Combo Boxes
View Scripting Functions List and Combo Box

lbDeleteString
Deletes the first entry from a list or combo box that begins with a specified
string.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.lbDeleteString strListBoxWinName, strToDelete

ViewScript syntax
lbDeleteString lbWinName, strToDelete

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strListBoxWinName lbWinName The name of the list or combo box
window.
strToDelete strToDelete String expression indicating the first
characters of the entry or entries to be
deleted. Use a literal string or STRING
variable.

Comments
You can define tab stops within a list box string by inserting the tab
character. The tab character is defined in the Inspector on the list box, and
defaults to '~'. For example, "Monday~Tuesday~Friday" would result in three
columns, each ~ replaced by the values, in pixels, defined by the Tab Stops
property. When manipulating this string, the tab stops must be included.
When using this function in an Active Scripting language (such as VBScript),
names of all items and variables in parameters must be written as string
expressions.
Note: If multiple strings begin with strToDelete, lbDeleteString deletes only the first string that
matches it. For example, if "Worked", "Working", and "Works" are all entries in the list box, using
"Work" in strToDelete would remove only the first item that appears in the list.

Return Value
If successful, this function returns the number of strings remaining in the list.
If lbWinname could not be found or strToDelete is invalid, this function
returns -1.

ViewScript Examples
Example 1: The following ViewScript example deletes all entries that begin
with "North" from the "MyComboBox" combo box.
lbDeleteString MyComboBox, "North"

Example 2: The following ViewScript example deletes all entries that begin
with "Recipe3" from the "RecipeList" list box and displays an error message if
the procedure is unsuccessful. "RetVal" is a variable being used to store the
return value.
retVal := lbDeleteString RecipeList, "Recipe3"
IF retVal = -1
Message "Unable to delete item."
ENDIF

Active Scripting Examples


Example 1: The following VBScript example deletes all entries that begin with
"North" from the "MyComboBox" combo box.
View.lbDeleteString "MyComboBox", "North"

Example 2: The following VBScript example deletes all entries that begin with
"Recipe3" from the "RecipeList" list box and displays an error message if the
procedure is unsuccessful. "RetVal" is a variable being used to store the
return value.
retVal.Value = View.lbDeleteString ("RecipeList", "Recipe3")
If retVal.Value = -1 Then
View.Message "Unable to delete item."
End If

See Also
lbDeleteStringAtIndex, lbEmpty, lbAddString, lbInsertString, Working With
List Boxes, Working With Combo Boxes
View Scripting Functions List and Combo Box

lbDeleteStringAtIndex
Deletes a string at a specific zero-based index from a list or combo box.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.lbDeleteStringAtIndex strListBoxWinName, numIndex

ViewScript syntax
lbDeleteStringAtIndex lbWinName, numIndex

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strListBoxWinName lbWinName The name of the list or combo box
window.
numIndex numIndex Integer indicating the zero-based index of
the string you want deleted.

Return Value
If successful, this function returns the number of strings remaining in the list.
If lbWinname could not be found or numIndex is invalid, this function returns -
1.

Comments
When using this function in an Active Scripting language (such as VBScript),
names of all items and variables in parameters must be written as string
expressions.

ViewScript Examples
Example 1: The following ViewScript example deletes the string located at
index 2 from the "MyComboBox" combo box.
lbDeleteStringAtIndex MyComboBox, 2
Example 2: The following ViewScript example deletes the string located at
index 0 from the "RecipeList" list box and displays an error message if the
procedure is unsuccessful. "RetVal" is a variable being used to store the return
value.
retVal := lbDeleteStringAtIndex RecipeList, 0
IF retVal = -1
Message "Unable to delete item."
ENDIF

Active Scripting Examples


Example 1: The following VBScript example deletes the string located at index
2 from the "MyComboBox" combo box.
View.lbDeleteStringAtIndex "MyComboBox", 2
Example 2: The following VBScript example deletes the string located at index
0 from the "RecipeList" list box and displays an error message if the procedure
is unsuccessful. "RetVal" is a variable being used to store the return value.
retVal.Value = View.lbDeleteStringAtIndex ("RecipeList", 0)
IF retVal.Value = -1 Then
View.Message "Unable to delete item."
End If

See Also
lbDeleteString, lbEmpty, lbAddString, lbInsertString, Working With List Boxes,
Working With Combo Boxes
View Scripting Functions List and Combo Box

lbEmpty
Removes the contents of a list or combo box.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.lbEmpty strListBoxWinName

ViewScript syntax
lbEmpty lbWinName

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strListBoxWinName lbWinName The name of the list or combo box window
you want to empty.

Return Value
None.

Comments
When using this function in an Active Scripting language (such as VBScript),
names of all items and variables in parameters must be written as string
expressions.

ViewScript Example
The following ViewScript example removes all entries from the "MyListBox"
list box.
lbEmpty MyListBox

Active Scripting Example


This sample is the same as above, written in VBScript.
View.lbEmpty "MyListBox"

See Also
lbDeleteString, lbDeleteStringAtIndex, Working With List Boxes, Working With
Combo Boxes
View Scripting Functions List and Combo Box

lbFillWithDirectory
Adds a list of filenames to a list or combo box.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.lbFillWithDirectory strListBoxWinName, strPath

ViewScript syntax
lbFillWithDirectory lbWinName, strPath

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strListBoxWinName lbWinName The name of the list or combo box
window.
strPath strPath String expression indicating the directory
path to the files you want listed. You can
use either a literal string or a STRING
variable.

Return Value
If no file names could be added to the list or the combo box, the function
returns -1.
If the list box or combo box already has the maximum number of entries, the
function returns -2.
Otherwise, the function returns the 0-based index of the final item added to
the list or combo box.
Note: If there are no files in the directory indicated by strPath, the function is considered to have
failed and will return -1.

Comments
When using this function in an Active Scripting language (such as VBScript),
names of all items and variables in parameters must be written as string
expressions.
New items are added after existing items in the list or combo box. For
example, if there are three items in the list or combo box (numbered from 0
to 2), and there are five files in the directory, the new filenames items are
added with index of 3, 4, 5, 6, and 7. The return value in this case would be
7.

ViewScript Example
The following ViewScript example fills the "RecipeList" list box with a listing of
all text files found in c:\tcp\myfolder.
MyLastIndex := lbFillWithDirectory RecipeList,
"c:\tcp\myfolder\*.txt"

Active Scripting Example


This sample is the same as above, written in VBScript.
MyLastIndex.Value = View.lbFillWithDirectory ("RecipeList",
"c:\tcp\myfolder\*.txt")

See Also
lbAddString, lbEmpty, Working With List Boxes, Working With Combo Boxes
View Scripting Functions List and Combo Box

lbFindString
Finds the first string in a list or combo box that begins with a specified string.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.lbFindString strListBoxWinName, strName

ViewScript syntax
lbFindString lbWinName, strName

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strListBoxWinName lbWinName The name of the list or combo box
window.
strName strName String expression indicating the first
characters of the string you want to find.
You can use either a literal string or
STRING variable.

Return Value
If successful, this function returns the zero-based index of the first string that
matches strName.
If lbWinname could not be found or strName is invalid, this function returns -
1.

Comments
You can define tab stops within a list box string by inserting the tab
character. The tab character is defined in the Inspector on the list box, and
defaults to '~'. For example, "Monday~Tuesday~Friday" would result in three
columns, each ~ replaced by the values, in pixels, defined by the Tab Stops
property. When manipulating this string, the tab stops must be included.
When using this function in an Active Scripting language (such as VBScript),
names of all items and variables in parameters must be written as string
expressions.
If multiple strings begin with strName, lbSelectString selects and returns the
index of the first string that matches. For example, if "Worked", "Working",
and "Works" are all entries in the list box (in that order), using "Work" in
strName would select "Worked". If only "Working" and "Works" are entries,
the function would select "Working".
Tips

● To find an exact string (where the matched string must also be of the same length as
strName), use lbFindStringExact.
● To both find and select a string, use lbSelectString.

ViewScript Examples
Example 1: The following ViewScript example searches for a string by its
prefix "New" in the "NewFeatures" combo box.
lbFindString NewFeatures, "New"

Example 2: The following ViewScript example searches for a string by its


prefix "Rec" in the "RecipeList" list box and display an error message if the
procedure is unsuccessful. "RetVal" is a variable being used to store the
return value.
retVal := lbFindString RecipeList, "Rec"
IF retVal = -1
Message "Unable to find item."
ENDIF

Active Scripting Examples


Example 1: The following VBScript example searches for a string by its prefix
"New" in the "NewFeatures" combo box.
View.lbFindString "NewFeatures", "New"

Example 2: The following VBScript example searches for a string by its prefix
"Rec" in the "RecipeList" list box and display an error message if the
procedure is unsuccessful. "RetVal" is a variable being used to store the
return value.
retVal.Value = View.lbFindString ("RecipeList", "Rec")
If retVal.Value = -1 Then
View.Message "Unable to find item."
End If

See Also
lbFindStringExact, lbGetCurSel, lbGetSelString, lbGetString, Working With List
Boxes, Working With Combo Boxes
View Scripting Functions List and Combo Box

lbFindStringExact
Finds a string in a list or combo box. With lbFindStringExact, you must specify
the entire string that you want to match.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.lbFindStringExact strListBoxWinName, strName

ViewScript syntax
lbFindStringExact lbWinName, strName

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strListBoxWinName lbWinName The name of the list or combo box
window.
strName strName String expression indicating the string you
want to find. You can use either a literal
string or STRING variable.

Return Value
If successful, the function returns the zero-based index of the string that was
found.
If the list box or combo box could not be found, if strName is invalid, or if no
string matching strName could be found, the function returns -1.

Comments
You can define tab stops within a list box string by using the Tab Character.
You specify which character designates a tab in the List Box object's Tab
Character property; by default it is a tilde (~). For example,
"Monday~Tuesday~Friday" indicates result in three columns, with each ~
replaced by the values, in pixels, defined by the Tab Stops property. When
manipulating this string, the tab stops must be included.
When using this function in an Active Scripting language (such as VBScript),
names of all items and variables in parameters must be written as string
expressions.
Any string matches must match strName exactly. For example, if a list box
had only "Worked" and "Working", calling lbFindStringExact with strName set
to "Work" would return -1 (since none of the strings match "Work" exactly).
Tips

● To find a string by specifying only the first few characters, use lbFindString.
● To both find and select a string, use lbSelectString.

ViewScript Examples
Example 1: The following ViewScript example searches for "MeetingRoom11"
in the "MeetingRooms" combo box.
lbFindStringExact MeetingRooms, "MeetingRoom11"

Example 2: The following ViewScript example searches for "Recipe2" in the


"RecipeList" list box and displays an error message if the procedure is
unsuccessful. "RetVal" is a variable being used to store the return value.
retVal := lbFindStringExact RecipeList, "Recipe2"
IF retVal = -1
Message "Unable to find item."
ENDIF

Active Scripting Examples


Example 1: The following VBScript example searches for "MeetingRoom11" in
the "MeetingRooms" combo box.
View.lbFindStringExact "MeetingRooms", "MeetingRoom11"

Example 2: The following VBScript example searches for "Recipe2" in the


"RecipeList" list box and displays an error message if the procedure is
unsuccessful. "RetVal" is a variable being used to store the return value.
retVal.Value = View.lbFindStringExact ("RecipeList", "Recipe2")
If retVal.Value = -1 Then
View.Message "Unable to find item."
End If

See Also
lbGetCurSel, lbGetSelString, lbGetString, lbFindString, lbSelectString,
Working With List Boxes, Working With Combo Boxes
View Scripting Functions List and Combo Box

lbGetCount
Retrieves the number of entries in a list or combo box.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.lbGetCount strListBoxWinName

ViewScript syntax
lbGetCount lbWinName

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strListBoxWinName lbWinName The name of the list or combo box
window.

Return Value
If successful, this function returns the number of entries in the list or combo
box.
If lbWinname could not be found, this function returns -1.

Comments
When using this function in an Active Scripting language (such as VBScript),
names of all items and variables in parameters must be written as string
expressions.

ViewScript Example
The following ViewScript example counts the number of entries within the
"RecipeList" list box, and stores the value in the variable "retVal".
retVal := lbGetCount RecipeList

Active Scripting Example


This sample is the same as above, written in VBScript.
retVal.Value = View.lbGetCount ("RecipeList")

See Also
lbGetCurSel, lbGetItemData, lbGetSelString, lbGetString, Working With List
Boxes, Working With Combo Boxes
View Scripting Functions List and Combo Box

lbGetCurSel
Returns the zero-based index value of the currently selected entry, if any, in
a list or combo box.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.lbGetCurSel strListBoxWinName

ViewScript syntax
lbGetCurSel lbWinName

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strListBoxWinName lbWinName The name of the list or combo box
window.

Return Value
If successful, this function returns the zero-based index of the currently-
selected entry.
If lbWinname could not be found or no entry is currently selected, this
function returns -1.

Comments
When using this function in an Active Scripting language (such as VBScript),
names of all items and variables in parameters must be written as string
expressions.

ViewScript Examples
Example 1: The following ViewScript example retrieves the index value of the
current selection within the "MeetingRoom" list box.
lbGetCurSel MeetingRoom
Example 2: The following ViewScript example retrieves the index value of the
current selection within the "RecipeList" list box and display an error message
if the procedure is unsuccessful. "RetVal" is a variable being used to store the
return value.
retVal := lbGetCurSel RecipeList
IF retVal = -1
Message "Unable to return index."
ENDIF

Active Scripting Examples


Example 1: The following VBScript example retrieves the index value of the
current selection within the "MeetingRoom" list box.
View.lbGetCurSel "MeetingRoom"
Example 2: The following VBScript example retrieves the index value of the
current selection within the "RecipeList" list box and display an error message
if the procedure is unsuccessful. "RetVal" is a variable being used to store the
return value.
retVal.Value = View.lbGetCurSel ("RecipeList")
If retVal.Value = -1 Then
View.Message "Unable to return index."
End If

See Also
lbSetCurSel, lbGetCount, lbGetItemData, lbGetSelString, lbGetString,
Working With List Boxes, Working With Combo Boxes
View Scripting Functions List and Combo Box

lbGetItemData
Returns the 32-bit value (cookie) associated with a list or combo box entry.
Use the lbGetItemData script function to get a cookie value.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.lbGetItemData strListBoxWinName, numIndex

ViewScript syntax
lbGetItemData lbWinName, numIndex

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strListBoxWinName lbWinName The name of the list or combo box
window.
numIndex numIndex Integer indicating the zero-based index of
the string.

Return Value
If successful, this function returns the 32-bit value associated with the entry.
If lbWinname could not be found or numIndex is invalid, this function returns -
1.

Comment
'Cookie' is a term referring to a positive integer that you can associate with a
string.
When using this function in an Active Scripting language (such as VBScript),
names of all items and variables in parameters must be written as string
expressions.

ViewScript Example
The following ViewScript example retrieves the cookie value from the string
located at index 2 in the "RecipeList" list box. "RetVal" is a variable being used
to store the return value.
setpoint := lbGetItemData RecipeList, 2

Active Scripting Example


This sample is the same as above, written in VBScript.
setpoint.Value = View.lbGetItemData ("RecipeList", 2)

See Also
lbSetItemData, lbGetCount, lbGetCurSel, lbGetString, Working With List
Boxes, Working With Combo Boxes
View Scripting Functions List and Combo Box

lbGetSelString
Searches for the selected string in a list or combo box and copies it into a
variable.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.lbGetSelString strListBoxWinName, strVarStoreInName

ViewScript syntax
lbGetSelString lbWinName, strVarStoreIn

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strListBoxWinName lbWinName The name of the list or combo box
window.
strVarStoreInName strVarStoreIn The name of the STRING variable to
which you want the string copied.

Return Value
If successful, this function returns the length of the string that was copied
into strVarStoreIn or strVarStoreInName, in bytes.
If lbWinname or strListBoxWinName could not be found or there is no active
selection, this function returns -1.

Comments
When using this function in an Active Scripting language (such as VBScript),
names of all items and variables in parameters must be written as string
expressions.

ViewScript Example
The following ViewScript example searches for the current selection within
"RecipeList" and copy it to the "RecipeActive" STRING variable. If the
procedure is unsuccessful, an error message is displayed.
retVal := lbGetSelString RecipeList, RecipeActive
IF retVal = -1
Message "Unable to copy item."
ENDIF

Active Scripting Example


This sample is the same as above, written in VBScript.
retVal.Value = View.lbGetSelString ("RecipeList", RecipeActive.Name)
If retVal.Value = -1 Then
View.Message "Unable to copy item."
End If

See Also
lbGetCurSel, lbGetString, lbGetItemData, lbGetCount, Working With List
Boxes, Working With Combo Boxes
View Scripting Functions List and Combo Box

lbGetString
Searches for a string at a specific zero-based index in a list or combo box and
copies the string into a variable.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.lbGetString strListBoxWinName, numIndex, strVarStoreInName

ViewScript syntax
lbGetString lbWinName, numIndex, strVarStoreIn

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strListBoxWinName lbWinName The name of the list or combo box
window.
numIndex numIndex Integer indicating the zero-based index of
the string you want copied.
strVarStoreInName strVarStoreIn The name of the variable you want the
string copied to.

Return Value
If successful, this function returns the length of the string copied into
strVarStoreIn, in bytes.
If lbWinname or strListBoxWinName could not be found, or numIndex is
invalid, this function returns -1.

Comments
When using this function in an Active Scripting language (such as VBScript),
names of all items and variables in parameters must be written as string
expressions.

ViewScript Example
The following ViewScript example copies the string located at index 2 from
"RecipeList" into the "RecipeContents" STRING variable and display an error
message if the procedure is unsuccessful.
retVal := lbGetString RecipeList, 2, RecipeContents
IF retVal = -1
Message "Unable to copy item."
ENDIF

Active Scripting Example


This sample is the same as above, written in VBScript.
retVal.Value = View.lbGetString ("RecipeList", 2,
RecipeContents.Name)
If retVal.Value = -1 Then
View.Message "Unable to copy item."
End If

See Also
lbGetSelString, lbGetCurSel, lbGetItemData, lbGetCount, Working With List
Boxes, Working With Combo Boxes
View Scripting Functions List and Combo Box

lbInsertString
Inserts a string into a list or combo box at a specific zero-based index. Unlike
the lbAddString function, lbInsertString does not cause a list whose Sorted
property is set to be sorted.
Tip: To be able to sort lists alphabetically, call the lbAddString script function.

Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.lbInsertString strListBoxWinName, strNewString, numAtIndex

ViewScript syntax
lbInsertString lbWinName, strNewString, numAtIndex

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strListBoxWinName lbWinName The name of the list or combo box
window.
strNewString strNewString String expression indicating the name of
the string you want inserted. You can use
either a literal string or a STRING
variable.
numAtIndex numAtIndex Integer indicating the zero-based index of
the position you want the string to be
inserted (that is, to insert the string at the
beginning of the list, use 0).
Note: You cannot insert an empty string into a List Box or Combo Box.

Return Value
If successful, this function returns the zero-based index position of the string
that was inserted (that is, the same value as numAtIndex).
If lbWinname or strListBoxWinName could not be found, or numAtIndex is
invalid, this function returns -1.
If the list box or combo box already has the maximum number of entries, the
function returns -2.

Comments
You can define tab stops within a list box string by inserting the tab
character. The tab character is defined in the Inspector on the list box, and
defaults to '~'. For example, "Monday~Tuesday~Friday" would result in three
columns, each ~ replaced by the values, in pixels, defined by the Tab Stops
property. When manipulating this string, the tab stops must be included.
When using this function in an Active Scripting language (such as VBScript),
names of all items and variables in parameters must be written as string
expressions.

ViewScript Example
The following ViewScript example inserts "Temperature" at index 2 in the
"ConditionList" list box and display an error message if the procedure is
unsuccessful.
retVal := lbInsertString ConditionList, "Temperature", 2
IF retVal = -1
Message "Unable to insert item."
ENDIF

Active Scripting Example


This sample is the same as above, written in VBScript.
retVal.Value = View.lbInsertString ("ConditionList", "Temperature",
2)
IF retVal.Value = -1 Then
View.Message "Unable to insert item."
End If

See Also
lbAddString, lbDeleteString, lbDeleteStringAtIndex, Working With List Boxes,
Working With Combo Boxes
View Scripting Functions List and Combo Box

lbSelectString
Searches for the first string or string prefix in a list or combo box, returning
the zero-based index of the first matching entry.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.lbSelectString strListBoxWinName, strToSelect

ViewScript syntax
lbSelectString lbWinName, strToSelect

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strListBoxWinName lbWinName The name of the list or combo box
window.
strToSelect strToSelect String expression indicating the first
characters of the entry or entries to
select. Use a literal string or a STRING
variable.

Return Value
If successful, this function returns the zero-based index of the selected string.
If lbWinname or strListBoxWinName could not be found, or strToSelect is
invalid, this function returns -1.

Comments
You can define tab stops within a list box string by inserting the tab
character. The tab character is defined in the Inspector on the list box, and
defaults to '~'. For example, "Monday~Tuesday~Friday" would result in three
columns, each ~ replaced by the values, in pixels, defined by the Tab Stops
property. When manipulating this string, the tab stops must be included.
When using this function in an Active Scripting language (such as VBScript),
names of all items and variables in parameters must be written as string
expressions.
If multiple strings match strToSelect, lbSelectString selects and returns the
index of the first string that matches. For example, if "Worked", "Working",
and "Works" are all entries in the list box (in that order), using "Work" in
strToSelect would select "Worked". If only "Working" and "Works" are entries,
the function would select "Working".

ViewScript Example
The following ViewScript example searches for and selects "Recipe2" in the
"RecipeList" list box, displaying an error message if the procedure is
unsuccessful.
retVal := lbSelectString RecipeList, "Recipe2"
IF retVal = -1
Message "Unable to select item."
ENDIF

Active Scripting Example


This sample is the same as above, written in VBScript.
retVal.Value = View.lbSelectString ("RecipeList", "Recipe2")
If retVal.Value = -1 Then
View.Message "Unable to select item."
End If

See Also
lbFindString, lbFindStringExact, Working With List Boxes, Working With
Combo Boxes
View Scripting Functions List and Combo Box

lbSetCurSel
Finds a string at a specific zero-based index and changes it to the current
selection. When the new string is selected, the previously selected string is
no longer selected.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.lbSetCurSel strListBoxWinName, numIndex

ViewScript syntax
lbSetCurSel lbWinName, numIndex

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strListBoxWinName lbWinName The name of the list or combo box
window.
numIndex numIndex Integer indicating the zero-based index
value of the string you want selected.

Return Value
If successful, this function returns the zero-based index position of the string
that was selected.
If lbWinname or strListBoxWinName could not be found, or numIndex is
invalid, this function returns -1.

Comments
When using this function in an Active Scripting language (such as VBScript),
names of all items and variables in parameters must be written as string
expressions.

ViewScript Example
The following ViewScript example selects the string at index 1 within the
"RecipeList" list box and displays an error message if the procedure is
unsuccessful.
retVal := lbSetCurSel RecipeList, 1
IF retVal = -1
Message "Unable to select item."
ENDIF

Active Scripting Example


This sample is the same as above, written in VBScript.
retVal.Value = View.lbSetCurSel ("RecipeList", 1)
If retVal.Value = -1 Then
View.Message "Unable to select item."
End If

See Also
lbGetCurSel, Working With List Boxes, Working With Combo Boxes
View Scripting Functions List and Combo Box

lbSetItemData
Sets a 32-bit value (cookie) associated with a list or combo box entry. This is
useful in applications that require you to associate a numeric value with a
string. You can then retrieve the cookie value by using the lbGetItemdata
function.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.lbSetItemData strListBoxWinName, numAtIndex, numCookie

ViewScript syntax
lbSetItemData lbWinName, numAtIndex, numCookie

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strListBoxWinName lbWinName The name of the list or combo box
window.
numAtIndex numAtIndex Integer indicating the zero-based index of
a list or combo box entry.
numCookie numCookie Integer indicating the value to associate
with the string.

Return Value
If successful, this function returns 1.
If lbWinname or strListBoxWinName could not be found, or numAtIndex is
invalid, this function returns -1.

Comment
Cookie is a term referring to a positive integer that you can associate with a
string.
When using this function in an Active Scripting language (such as VBScript),
names of all items and variables in parameters must be written as string
expressions.
ViewScript Example
The following ViewScript example assigns a cookie value of 100 to the entry
located at index 2 in the "RecipeList" list box, and displays an error message
if the procedure is unsuccessful.
retVal := lbSetItemData RecipeList, 2, 100
IF retVal = -1
Message "Unable to assign cookie."
ENDIF

Active Scripting Example


This sample is the same as above, written in VBScript.
retVal.Value = View.lbSetItemData ("RecipeList", 2, 100)
If retVal.Value = -1 Then
View.Message "Unable to assign cookie."
End If

See Also
lbGetItemData, Working With List Boxes, Working With Combo Boxes
View Scripting Functions

Log File script functions

Log file functions allow you to manually log information to ASCII text files.
This lets you log specific messages and values to track processes in your
system.
By default, log files are stored in the following directories:

● On Windows PC targets, log files are stored in


"fxView\Runtime\PROJECT\WebRoot\History\ProjectName" under the
Machine Edition installation directory, where ProjectName is the name of
your project. By default, Machine Edition is installed to "C:\Program
Files\GE IP\Proficy Machine Edition".
● QuickPanel View/Control units store the log files in the root directory.

You can specify a different location for a log file by including a path name
when creating a new log file.
Tip: You can also assign variables to logging groups and generate trending charts for that data.
For more information on logging groups, see Logging: an Overview.

The following functions are available:

Function Description
LogCloseFile Close a logging file.
LogDate Log the date.
LogElapsed Log elapsed time.
LogFileExists Verifies that a file exists.
LogNewFile Creates a new file and starts logging.
LogNewLine Resumes logging on a new line.
LogOpenFile Open a logging file.
LogPrintString Print a string to a logging file.
LogPrintValue Print a value to a logging file.
LogSetUseComma Set values to be separated by commas.
LogTime Log the time to a logging file.
View Scripting Functions Log File

LogCloseFile
Closes the specified logging file.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.LogCloseFile numFileHandle

ViewScript syntax
LogCloseFile numFileHandle

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
numFileHandle numFileHandle The handle of the logging file returned by
LogOpenFile or LogNewFile.

Return Value
This function returns 1 if successful, -1 otherwise.

ViewScript Example
The following ViewScript example closes the logging file 'Logfile', whose file
handle is stored in the variable 'FileOne'.
FileOne := LogOpenFile "Logfile"
...
MyCloseFileStatus := LogCloseFile FileOne

Active Scripting Example


This sample is the same as above, written in VBScript.
FileOne.Value = View.LogOpenFile ("Logfile")
...
MyCloseFileStatus.Value = View.LogCloseFile (FileOne.Value)

See Also
LogOpenFile, LogNewFile
View Scripting Functions Log File

LogDate
Logs the date to a logging file.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.LogDate numFileHandle

ViewScript syntax
LogDate numFileHandle

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
numFileHandle numFileHandle The handle of the logging file returned by
LogOpenFile or LogNewFile.

Return Value
This function returns 1 if successful, -1 otherwise.

Comments
By default, a comma is appended to the date. This behavior can be changed
for an open log file by calling the LogSetUseComma function.
The format in which the date is logged depends on which Machine Edition
Language Pack is installed.

● If no Language Pack is installed (that is, the language is English), the


date is logged in YYYY/MM/DD format.
● If the installed Language Pack is German, Spanish, French, Italian,
Czech, or Russian, the format is DD/MM/YYYY.
● If the installed Language Pack is Polish, the format is MM/DD/YYYY.

ViewScript Example
The following ViewScript example logs the date to the logging file 'FileOne':
MyDateStatus := LogDate FileOne

Active Scripting Example


This sample is the same as above, written in VBScript.
MyDateStatus.Value = View.LogDate (FileOne.Value)

See Also
LogTime
View Scripting Functions Log File

LogElapsed
Logs the elapsed time (in seconds) since the last call to LogElapsed. The
timer is started on the first call to LogElapsed. Data is logged to a logging file
opened with LogOpenFile or LogNewFile.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.LogElapsed numFileHandle [, 0]

ViewScript syntax
LogElapsed numFileHandle [, 0]

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
numFileHandle numFileHandle The handle of the logging file returned by
LogOpenFile or LogNewFile.
0 0 (Optional) Passing a zero as the second
parameter resets the elapsed time to zero
and logs "0" to the log file.

Return Value
This function returns 1 if successful, -1 otherwise.

Comments
The LogElapsed timer is reset if the logging file is closed and then reopened,
even if you are logging to the same file as the last call to LogElapsed.
By default, a comma is appended to the number of seconds. This behavior
can be changed for an open log file by calling the LogSetUseComma function.
A "0" is logged the first time LogElapsed is called and when LogElapsed is
called with the optional 0 parameter.

ViewScript Example
The following ViewScript example logs the elapsed time in seconds since the
last LogElapsed call to 'FileOne':
MyTimeStatus := LogElapsed FileOne

Active Scripting Example


This example is the same as above, written in VBScript.
MyTimeStatus.Value = View.LogElapsed (FileOne.Value)

See Also
LogTime, LogDate
View Scripting Functions Log File

LogFileExists
Verifies that the specified log file already exists.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.LogFileExists strFileName [, numFileExtension]

ViewScript syntax
LogFileExists strFileName [, numFileExtension]
Parameters (see Naming Conventions)
Active Scripting ViewScript Description
strFileName strFileName String expression indicating the name of
the file into which you want logging to be
written. The filename can include a full
path.
numFileExtension numFileExtension (Optional) If this parameter is used, it
used as a file name extension (as in
"Recipe.900"). This allows multiple files to
be logged using a variable to differentiate
the file names.
Note: numFileExtension must be from -99 through 999. Values less than -99 are assumed to be -
99; values greater than 999 are assumed to be 999.

Return Value
This function returns 1 if the specified log file exists, -1 otherwise.

ViewScript Example
The following ViewScript example verifies that the logging file "Recipe.900"
exists.
MyLogFileExists := LogFileExists "Recipe", 900

Active Scripting Example


This sample is the same as above, written in VBScript.
MyLogFileExists.Value = View.LogFileExists ("Recipe", 900)

See Also
LogNewFile, LogOpenFile
View Scripting Functions Log File

LogNewFile
Creates and opens a new file, if the file does not already exist. If the file
already exists, it is overwritten. Returns a file handle.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.LogNewFile strFileName, [, numExtension]

ViewScript syntax
LogNewFile strFileName, [, numExtension]

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strFileName strFileName String expression containing the name of
the file into which you want logging to be
entered. The filename can include a full
path. If an invalid path is specified, View
Runtime uses the directory where the
project is stored on the local computer or
unit.
numExtension numExtension (Optional) If this parameter is used, it
used as a file name extension (as in
"Recipe.900"). This allows multiple files to
be logged using a variable to differentiate
the file names.
Note: The extension must be between -99 and 999. If a number is less than -99 it is changed to -
99; if a number greater than 999 is passed it will be changed to 999.

Return Value
Returns an integer value as a file handle.
Note: If an error occurs this value will be -1 otherwise it will be a positive integer. A maximum of 16
files may be in use at any one time.

Comments
Since this function automatically opens the log file it creates, using
LogOpenFile is not necessary. However, your script should still close the new
log file when you're done with it.

ViewScript Example
The following ViewScript example creates and opens the file 'Logfile', with the
extension 'Extvar'. The resulting log file handle is stored in the variable
myHandle.
myHandle := LogNewFile "Logfile", Extvar

Active Scripting Example


This sample is the same as above, written in VBScript.
myHandle.Value = View.LogNewFile ("Logfile", Extvar.Value)

See Also
LogOpenFile, LogCloseFile
View Scripting Functions Log File

LogNewLine
Resumes logging on a new line of the specified file.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.LogNewLine numFileHandle

ViewScript syntax
LogNewLine numFileHandle

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
numFileHandle numFileHandle The handle of the logging file returned by
LogOpenFile or LogNewFile.

Return Value
This function returns 1 if successful, -1 otherwise.

ViewScript Example
The following ViewScript example starts a new line in logging file 'FileOne':
MyNewLineStatus := LogNewLine FileOne

Active Scripting Example


This sample is the same as above, written in VBScript.
MyNewLineStatus.Value = View.LogNewLine (FileOne.Value)

See Also
LogSetUseComma
View Scripting Functions Log File

LogOpenFile
Opens an existing log file for additional logging.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.LogOpenFile strFileName [, numExtension]

ViewScript syntax
LogOpenFile strFileName [, numExtension]

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strFileName strFileName String expression indicating the name of
the file in which you want to store logged
information. The filename can include a full
path. If an invalid path is specified, View
Runtime uses the directory where the
project is stored on the local computer or
unit.
numExtension numExtension (Optional) If this parameter is used, it
used as a file name extension (as in
"Recipe.900"). This allows multiple files to
be logged using a variable to differentiate
the file names.
Note: The extension must be between -99 and 999. If a number is less than -99 it is changed to -
99; if a number greater than 999 is passed, it will be changed to 999.

Return Value
When a file is opened an integer file handle is returned. The file handle is
passed to the other functions to let them know which file is being operated
on.
Note: If an error occurs this value will be -1 otherwise it will be a positive integer. A maximum of 16
files may be in use at any one time.
ViewScript Example
The following ViewScript example opens the file "Logfile" and appends the
value of 'Extvar'. The resulting log file handle is stored in the variable
myHandle.
myHandle := LogOpenFile "Logfile", Extvar

Active Scripting Example


This sample is the same as above, written in VBScript.
myHandle.Value = View.LogOpenFile ("Logfile", Extvar.Value)

See Also
LogCloseFile
View Scripting Functions Log File

LogPrintString
Prints a string to the logging file.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.LogPrintString numFileHandle [, strString]

ViewScript syntax
LogPrintString numFileHandle [, strString]

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
numFileHandle numFileHandle The handle of the logging file returned by
LogOpenFile or LogNewFile.
strString strString (Optional) String expression indicating the
text to print to the log file.
Tips

● When using string constants, make sure you


separate the parameter values correctly,
enclosing the entire comma-separated list within
quotation marks.
● In ViewScript, the ^ character is an escape
character. Quotation marks within the
parameter list should be preceded with the ^
character, as in "^"hello world^"".
● In VBScript, quotation marks within the
parameter list should be preceded with another
", as in ""hello world"".

Return Value
This function returns 1 if successful, -1 otherwise.
Comments
By default, a comma is appended to the text indicated in strString. This
behavior can be changed for an open log file by calling the LogSetUseComma
function.

ViewScript Example
The following ViewScript example prints the string "Morning Run" to the file
with file handle myHandle:
MyPrintStringStatus := LogPrintString myHandle, "Morning Run"

Active Scripting Example


This sample is the same as above, written in VBScript.
MyPrintStringStatus.Value = View.LogPrintString (myHandle.Value,
"Morning Run")

See Also
LogPrintValue
View Scripting Functions Log File

LogPrintValue
Prints a value to the logging file with specified precision.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.LogPrintValue numFileHandle, numValue [, numPrecision]

ViewScript syntax
LogPrintValue numFileHandle, numValue [, numPrecision]

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
numFileHandle numFileHandle The handle of the logging file returned by
LogOpenFile or LogNewFile.
numValue numValue This value will be printed to the logging
file.
numPrecision numPrecision (Optional) The number of decimal places
that numValue will be rounded to.
Note: The default precision is to six decimal places. The range of precision is between 0 and 30
inclusive.

Return Value
This function returns 1 if successful, -1 otherwise.

Comments
By default, a comma is appended to the value indicated in numValue. This
behavior can be changed for an open log file by calling the LogSetUseComma
function.

ViewScript Example
The following ViewScript example prints the value of 'temperature', rounded
to two decimal places, to the file with file handle myHandle:
MyPrintValueStatus := LogPrintValue myHandle, temperature, 2
Active Scripting Example
This sample is the same as above, written in VBScript.
MyPrintValueStatus.Value = View.LogPrintValue (myHandle.Value,
temperature.Value, 2)

See Also
LogPrintString
View Scripting Functions Log File

LogSetUseComma
Sets or removes the inclusion of commas when values are written to log files.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.LogSetUseComma numFileHandle [, numUseCommas]

ViewScript syntax
LogSetUseComma numFileHandle [, numUseCommas]

Parameters (see Naming Conventions)


Active Scripting ViewScript
Description
numFileHandle numFileHandle
The handle of the logging file returned by
LogOpenFile or LogNewFile.
numUseCommas numUseCommas (Optional) A DINT value indicating
whether commas should be included or
excluded.

● If 0, commas will not be included


with data logged to the file pointed
to by numFileHandle.
● If 1, a comma will be appended after
every value logged to the file pointed
to by numFileHandle.

Return Values
This function returns 1 if successful, -1 otherwise.

Comments
If the numUseCommas parameter is not included, the function turns commas
off.

ViewScript Examples
The following ViewScript example turns off the use of commas in the file
pointed to by myLogHandleA, and turns on commas in the file pointed to by
myLogHandleB.
MySetUseCommaStatus := LogSetUseComma myLogHandleA
MySetUseCommaStatus := LogSetUseComma myLogHandleB, 1

Active Scripting Examples


These samples are the same as above, written in VBScript.
MySetUseCommaStatus.Value = View.LogSetUseComma (myLogHandleA.Value)
MySetUseCommaStatus.Value = View.LogSetUseComma (myLogHandleB.Value,
1)

See Also
LogNewLine
View Scripting Functions Log File

LogTime
Logs the time in HH:MM:SS format to the logging file, using a 24-hour clock.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.LogTime numFileHandle

ViewScript syntax
LogTime numFileHandle

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
numFileHandle numFileHandle The handle of the logging file returned by
LogOpenFile or LogNewFile.

Return Value
This function returns 1 if successful, -1 otherwise.

Comments
By default, a comma is appended to the time. This behavior can be changed
for an open log file by calling the LogSetUseComma function.

ViewScript Example
The following ViewScript example logs the time to the logging file 'FileOne' in
HH:MM:SS format:
MyLogTimeStatus := LogTime FileOne

Active Scripting Example


This sample is the same as above, written in VBScript.
MyLogTimeStatus.Value = View.LogTime (FileOne.Value)

See Also
LogDate, LogElapsed
View Scripting Functions

Miscellaneous script functions

The following Miscellaneous Functions are available.


Function Description
ChangeDeviceParameters Change configuration for a device of a Modicon
TCP/IP driver.
Message Displays a standard dialog box with the message
provided as a parameter to the command.
NetChangeServer Toggles a Client target's data source between its
primary Server target and a backup Server target.
Random Allows you to generate a random integer number in
a specified range.
ToggleDiscrete Toggles the value of a discrete variable.
View Scripting Functions Miscellaneous

ChangeDeviceParameters
Change configuration for a device of a Modicon TCP/IP driver.
Supported by: Windows PC, QuickPanel View/Control targets

Active Scripting syntax


View.ChangeDeviceParameters strDeviceName, strParameters

ViewScript syntax
ChangeDeviceParameters strDeviceName, strParameters

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strDeviceName strDeviceName A string expression specifying the name of
the PLC Access I/O device that is to be
reconfigured.
strParameters strParameters A string expression specifying a series of
parameters that form the Address of the
indicated device. This must be valid based
on the Address format for the indicated
driver. For more details, see Comments
below.

Return Value
If the configuration command could not be sent to the driver, this function
returns 0.
If the configuration command was successfully sent to the driver, this
function returns 1.
Warning: This function does not check the content of strParameters, nor can it determine the
ultimate success or failure after the configuration command is sent to the Modicon TCP/IP driver.
The function returns 0 only if strDeviceName does not specify a valid device within the project.

Comments
This function reconfigures a device of a PLC Access I/O driver during run
time. It is supported only by a subset of PLC Access I/O drivers.
To determine the format for strParameters for a device of a specific driver,
see help for the device's Address property. (Click in the device's Address
property to open the Address configuration dialog box, then click Help.)
Tip: An easy way to determine strParameters for a desired configuration is to first configure the
device's Address in its Address configuration dialog box. Then, copy the string that is generated
from the property in the Inspector and Paste it into the script.

This function is supported only by the Modicon TCP/IP driver.

ViewScript Examples
Example: The following example reconfigures the device of a Modbus TCP/IP
driver:
ChangeDeviceParameters "MyMBTCPIPDevice", "1.2.3.4 -O1 -I9 -P502"

Active Scripting Examples


This sample is the same as above, written in VBScript.
Example 1:
View.ChangeDeviceParameters "MyMBTCPIPDevice", "1.2.3.4 -O1 -I9 -
P502"
View Scripting Functions Miscellaneous

Message
Displays a standard dialog box with the message displayed within the dialog.
You can also display buttons to be clicked or chosen from.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.Message strMessageString [, numChooseButton]

ViewScript syntax
Message strMessageString [, numChooseButton]

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strMessageString strMessageString String expression indicating the
message to display in the dialog box.
This can be a literal string or a STRING
variable.
numChooseButton numChooseButton Integer expression indicating the
buttons and icon to display in the dialog
box. The default is 65, indicating a
dialog box with OK and Cancel buttons
and the Information icon. See
Comments below for details.

Comments

Return Value
This function returns an integer indicating the button that was clicked:
1: OK
2: Cancel
3: Abort
4: Retry
5: Ignore
6: Yes
7: No

Comments
Do not use the VBScript MsgBox function when running runtime with the
target property "Keep as Topmost App" set to True. The message box will be
hidden behind the View Runtime window and the application will appear to
have halted, with all user input locked. Instead, use the View.Message
function.
Note: Only one message box created with the Message function will display at a time. If you
attempt to display a second message box while one already exists, the second call to Message will
be ignored.

Displaying Quotation marks: To display quotation marks within


strMessageString, do the following

● In ViewScript, add a caret (^) before each quotation mark. For example,
to display the message Motors are "ON", use:
Message "Motors are ^"ON^"."

● In VBScript, use two quotation marks for every printable single


quotation mark. For example, to display the message Motors are "ON",
use:
View.Message "Motors are ""ON""."

Displaying line breaks: To insert a line break within strMessageString, use \n


where you want the line to break. If the character sequence \n is part of the
text you want to display, add a second slash (\) , as in \\n (this prevents the
second "\" character from being interpreted as a special character).
Values for numChooseButton: The following tables indicate the possible
values for the numChooseButton parameter. Add one value from each column
to get the needed value. For example, to open a dialog box with Abort, Retry,
and Ignore buttons with an "Important" icon, use 51 (3+48) for
numChooseButton.
Message Box Buttons Message Box Icons
0: OK 0: No icon
1: OK/Cancel (default) 16: Warning
2: Abort/Retry/Ignore 32: Question
3: Yes/No/Cancel 48: Important
4: Yes/No 64: Information (default)
5: Retry/Cancel
Warning: When viewing QuickPanel View/Control HMI graphical panels remotely over the web
(see Remote Viewing of View Runtime), any dialog boxes that are opened because of actions
performed remotely on the HMI will not be closed on the QuickPanel View/Control display. This
will eventually cause the HMI application to fail. If you want to use a script function that opens a
dialog box on a QuickPanel View/Control target, it is highly recommended that you do not allow
users to operate the HMI remotely.

ViewScript Examples
Example 1: The following ViewScript example displays a message in
quotation marks, with an OK button for acknowledging the message.
Message "System A Motors have stopped", 0
Example 2: The following ViewScript example displays a message in
quotation marks with OK/Cancel buttons and a Question Icon. If the OK
button is clicked, start the motor sequence.
DECLARE _ReturnValue
_ReturnValue := Message "Start Motor A?", 33
' If user clicks OK, start motor sequence
IF _ReturnValue = 1
System_MotorA_Start := 1
ENDIF

Active Scripting Examples


Example 1: The following VBScript example displays a message in quotation
marks, with an OK button for acknowledging the message.
View.Message ("System A Motors have stopped", 0)
Example 2: The following VBScript example displays a message in quotation
marks with OK/Cancel buttons and a Question Icon. If the OK button is
clicked, start the motor sequence.
Dim ReturnValue
ReturnValue = View.Message ("Start Motor A?", 33)
' If user clicks OK, start motor sequence
If ReturnValue = 1 Then
System_MotorA_Start.Value = 1
End If
View Scripting Functions Miscellaneous

Random
Generates a random integer number in the range from the numMinRange to
the numMaxRange value.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.Random numMinRange, numMaxRange

ViewScript syntax
Random numMinRange, numMaxRange

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
numMinRange numMinRange The lowest number to be generated.
numMaxRange numMaxRange The highest number to be generated.

Return Value
The random number generated.

ViewScript Examples
Example 1: In the following ViewScript example, the variable 'RandomNum1'
receives a random number, not less than -100 and not greater than 100.
RandomNum1 := Random -100, 100
Example 2: In the following ViewScript example, the variable 'RandomNum2'
receives a random number, not less than -1000 and not greater than the
value of the variable 'Max'.
RandomNum2 := Random -1000, Max
Example 3: In the following ViewScript example, the variable 'RandomNum3'
receives a random number, not less than the value of the variable 'Min' and
not greater than the value of the variable 'Max'.
RandomNum3 := Random Min, Max

Active Scripting Examples


Example 1: In the following VBScript example, the variable 'RandomNum1'
receives a random number, not less than -100 and not greater than 100.
RandomNum1.Value = View.Random (-100, 100)
Example 2: In the following VBScript example, the variable 'RandomNum2'
receives a random number, not less than -1000 and not greater than the
value of the variable 'Max'.
RandomNum2.Value = View.Random (-1000, Max.Value)
Example 3: In the following VBScript example, the variable 'RandomNum3'
receives a random number, not less than the value of the variable 'Min' and
not greater than the value of the variable 'Max'.
RandomNum3.Value = View.Random (Min.Value, Max.Value)
View Scripting Functions Miscellaneous

ToggleDiscrete
Toggles the value of a BOOL (discrete) variable. If the variable's value is 0, it
becomes 1; if it is 1, it becomes 0.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.ToggleDiscrete strBOOLVarToToggleName

ViewScript syntax
ToggleDiscrete disvarVarToToggle

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strBOOLVarToToggleName disvarVarToToggle The name of a Machine Edition
BOOL variable.

Comments
When using this function in an Active Scripting language (such as VBScript),
names of all items and variables in parameters must be written as string
expressions. Also, strBOOLvarToToggleName cannot refer to a variable that is
locally defined in VBScript with a DIM statement.

Return Value
None

ViewScript Example
The following ViewScript example changes the value of the variable
'ConveyorMode'.
ToggleDiscrete ConveyorMode

Active Scripting Example


This sample is the same as above, written in VBScript.
View.ToggleDiscrete ConveyorMode.Name
View Scripting Functions Miscellaneous

NetChangeServer
Use NetChangeServer to toggle a Client target's data source between its
primary Server target and a backup Server target.
Note: The backup Server target is defined by the properties of the primary Server target.

Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.NetChangeServer strServerTargetName

ViewScript syntax
NetChangeServer strServerTargetName

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strServerTargetName strServerTargetName The name of the Client's primary
Server target. The parameter
must be either a literal string, or
a STRING variable.

Return Value
None

Comments
This function only works when you have a backup server configured for the
primary Server target.
If the primary Server target goes down and the client switches to the backup
Server target, the client does not switch back to the primary Server until
either the backup goes down, or you use this function.
Use NetChangeServer to switch to the backup Server before a planned
shutdown of the primary Server to minimize client connection time.
For more information on how networking works between targets (including
the relationship between Client, Server, and Backup targets), see
Networking: an Overview.
ViewScript Examples
Example 1: In the following ViewScript example, the Client target 'MyClient'
is reading data from its primary Server target, 'MyServer'. The Server target
'MyBackup' has been configured as a backup for 'MyServer'. Use
NetChangeServer to toggle the active server between 'MyServer' and
'MyBackup':
NetChangeServer "MyBackup"
'MyClient' now reads data from 'MyBackup'.
Example 2: To toggle the active server back to 'MyServer', repeat the same
line:
NetChangeServer "MyServer"

Active Scripting Examples


These samples are the same as above, written in VBScript.
Example 1:
View.NetChangeServer "MyBackup"
Example 2:
View.NetChangeServer "MyServer"
View Scripting Functions

Panel Management script functions

Panel management functions open, close, show, hide and/or print graphical
panels. When used without parameters , these functions affect all panels in
the project. If you want something done with a specific panel, use the name
of the panel as a parameter.
All panel management commands are subject to security levels in effect at
the time they are executed. For example, if a script containing a PanelOpen
command is executed while an operator is logged on with no PanelOpen
rights, no action takes place. For more information on runtime security, see
View Runtime Security. For a list of script functions relating to HMI security,
see View Security Script Functions.
The following Panel Management Functions are available:
Function Description
PanelClose Closes an open panel.
PanelHide Hides an open panel.
PanelIconize Minimizes an open panel.
PanelIndex Displays the panel open dialog box.
PanelOpen Opens a closed panel.
PanelPrint Prints an open panel.
PanelRestore Restores a minimized panel.
PanelShow Shows a hidden panel.
View Scripting Functions Panel Management

PanelClose
Closes a specified panel or all open panels in the HMI.
Note: This function is being deprecated and is not fully supported by remote views of graphical
panels (that is, when users view and use graphical panels over the web). In its place, we highly
recommend you use the "Close Panel" Touch Animation action.

Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.PanelClose [strPanelName]

ViewScript syntax
PanelClose [panName]

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strPanelName panName (Optional) The name of the panel. If not
specified, PanelClose closes all open
panels in the application.

Return Value
None

Comments
When using this function in an Active Scripting language (such as VBScript),
names of all items and variables in parameters must be written as string
expressions.

ViewScript Examples
Example 1: The following ViewScript example logs out the current user and
closes all open panels in the project:
Logoff
PanelClose
Example 2: The following ViewScript example closes the single panel
'PanelOne':
PanelClose PanelOne

Active Scripting Examples


Example 1: The following VBScript example logs out the current user and
closes all open panels in the project:
View.Logoff
View.PanelClose
Example 2: The following VBScript example closes the single panel
'PanelOne':
View.PanelClose "PanelOne"

See Also
PanelIndex, PanelOpen
View Scripting Functions Panel Management

PanelHide
Hides the specified panel or all currently-open panels in the HMI.
If you have a panel in your project that needs to be opened or closed multiple
times, you may find it faster to use Hide and Show instead.
Warning: A situation with all panels hidden is difficult to recover from. Hidden files do not show up
in the Panel Open dialog. The only way to recover from all panels being hidden is for an application
script to call PanelShow.

Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.PanelHide [strPanelName]

ViewScript syntax
PanelHide [panName]

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strPanelName panName (Optional) The name of the panel to hide.
If not specified, PanelHide hides all
currently-open panels in the HMI.

Return Value
None

Comments
After this command, the panel continues to update data in the background.
Panels such as chart object don't lose any data if hidden.
When using this function in an Active Scripting language (such as VBScript),
names of all items and variables in parameters must be written as string
expressions.

ViewScript Example
The following ViewScript example hides the panel 'PanelOne':
PanelHide PanelOne

Active Scripting Example


This sample is the same as above, written in VBScript.
View.PanelHide "PanelOne"

See Also
PanelClose, PanelOpen, PanelShow
View Scripting Functions Panel Management

PanelIconize
Minimizes a panel or all currently-open panels as icons at the bottom of the
HMI screen.
Supported by: Windows PC targets only

Active Scripting syntax


View.PanelIconize [strPanelName]

ViewScript syntax
PanelIconize [panName]

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strPanelName panName (Optional) The name of the panel to
iconize. If not supplied, all currently-
open panels are iconized.

Return Value
None

Comments
You can tell if a panel can be iconized if the minimize button is displayed in
the upper right corner of the panel.
This function only works if the panel's Thick Border, Caption, and System
Menu properties are True.
PanelIconize is not currently supported on QuickPanel View/Control units.
Warning: Panels that appear as icons may be confusing to operators of the HMI. Use this function
with caution.

When using this function in an Active Scripting language (such as VBScript),


names of all items and variables in parameters must be written as string
expressions.

ViewScript Example
The following ViewScript example iconizes the panel 'PanelOne':
PanelIconize PanelOne

Active Scripting Example


This sample is the same as above, written in VBScript.
View.PanelIconize "PanelOne"

See Also
PanelRestore
View Scripting Functions Panel Management

PanelIndex
Lets the user select a specific panel to open.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.PanelIndex

ViewScript syntax
PanelIndex

Comments
This function opens the Panel Open dialog box. The user can then select the
panel that he or she wants to open. Only panels that are not open—including
hidden panels—are listed.
Warning: When viewing QuickPanel View/Control HMI graphical panels remotely over the web
(see Remote Viewing of View Runtime), any dialog boxes that are opened because of actions
performed remotely on the HMI will not be closed on the QuickPanel View/Control display. This
will eventually cause the HMI application to fail. If you want to use a script function that opens a
dialog box on a QuickPanel View/Control target, it is highly recommended that you do not allow
users to operate the HMI remotely.

Return Value
None

See Also
PanelClose, PanelOpen
View Scripting Functions Panel Management

PanelOpen
Opens a panel or all closed panels in the HMI.
Warning: When using PanelOpen in a button script (for Touch Animation in which the action is to
"Run Script When Down"), the script will pause while the new panel is being opened. The script will
resume only when the original panel is opened again.
Note: This function is being deprecated and is not fully supported by remote views of graphical
panels (that is, when users view and use graphical panels over the web). In its place, we highly
recommend you use the "Open Panel" Touch Animation action.

Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.PanelOpen [strPanelName] [, numAtX, numAtY]

ViewScript syntax
PanelOpen [panName] [, numAtX, numAtY]

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strPanelName panName (Optional) The name of the panel to
open. Panel names must be provided
without quotation marks. If not supplied,
a Panel Selector dialog box appears,
letting the user select from all open
panels (the equivalent of calling the
PanelIndex function).
numAtX numAtX (Optional) The horizontal screen
coordinate to position the upper left
corner of the panel. If used, the numAtY
parameter must also be included.
numAtY numAtY (Optional) The vertical screen coordinate
to position the upper left corner of the
panel. If used, the numAtX parameter
must also be included.
Note: A negative x,y offset will place the panel in the top left corner of the runtime screen. A -x will
place the panel on the left edge of the screen, and a -y will place it on the top edge screen.

Return Value
None

Comments
When using this function in an Active Scripting language (such as VBScript),
names of all items and variables in parameters must be written as string
expressions.

ViewScript Example
The following ViewScript example opens the panel 'ErrorPanel', with the top
left corner of the panel positioned 300 pixels from the left side of the screen
and 500 pixels from the top of the screen.
PanelOpen ErrorPanel, 300, 500

Active Scripting Example


This sample is the same as above, written in VBScript.
View.PanelOpen "ErrorPanel", 300, 500

See Also
PanelClose, PanelIndex
View Scripting Functions Panel Management

PanelPrint
Prints a screenshot of a panel on the default printer.
Supported by: Windows PC and QuickPanel View/Control targets
Note: Currently, QuickPanel View/Control hardware does not support this function. You can still
include it in your scripts, but it will do nothing.

Active Scripting syntax


View.PanelPrint strPanelName

ViewScript syntax
PanelPrint panName

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strPanelName panName The name of the panel to print.

Return Value
None

Comments
If the panel contains animated objects, the snapshot of the panel captures
the animation display when the script is used.
When using this function in an Active Scripting language (such as VBScript),
names of all items and variables in parameters must be written as string
expressions.

ViewScript Example
The following ViewScript example prints the panel 'ReportPanel':
PanelPrint ReportPanel

Active Scripting Example


This sample is the same as above, written in VBScript.
View.PanelPrint "ReportPanel"

See Also
AlarmPrint, TrendPrint
View Scripting Functions Panel Management

PanelRestore
Restores (maximizes) an iconized panel or all iconized panels to the normal
position and size. This function also restores currently-maximized panels to
their original or normal size.
Supported by: Windows PC targets only

Active Scripting syntax


View.PanelRestore [strPanelName]

ViewScript syntax
PanelRestore [panName]

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strPanelName panName (Optional) The name of the panel to
restore. If not supplied, all iconized
panels are restored.

Return Value
None

Comments
This function only works on iconized or maximized panels. Hidden or closed
panels are not affected.
PanelRestore is not currently available on QuickPanel View/Control units.
When using this function in an Active Scripting language (such as VBScript),
names of all items and variables in parameters must be written as string
expressions.

ViewScript Example
The following ViewScript example restores the panel 'PanelOne' to its
configured size:
PanelRestore PanelOne
Active Scripting Example
This sample is the same as above, written in VBScript.
View.PanelRestore "PanelOne"

See Also
PanelIconize
View Scripting Functions Panel Management

PanelShow
Reactivates a hidden panel or all hidden panels.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.PanelShow [strPanelName]

ViewScript syntax
PanelShow [panName]

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strPanelName panName (Optional) The name of the hidden panel.
If not specified, all hidden panels are
shown.

Comments
When using this function in an Active Scripting language (such as VBScript),
names of all items and variables in parameters must be written as string
expressions.

Return Value
None

See Also
PanelClose, PanelHide, PanelOpen, PanelRestore
View Scripting Functions

Screen Navigation script functions

The following screen navigation functions are available:


Function Description
ScreenSelectObject Use this function to move the cursor over the object with
the name specified by the parameter.
ScreenSetCursorPos Allows you to set the cursor position in the specified
panel.
View Scripting Functions Screen Navigation

ScreenSelectObject
Moves the cursor selection to a specified graphical object.
Supported by: Windows PC targets only

Active Scripting syntax


View.ScreenSelectObject strObjectName

ViewScript syntax
ScreenSelectObject strObjectName

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strObjectName strObjectName String expression indicating the name of
the object over which you want the cursor
positioned. This object must use touch
animation, slider animation, or value
animation with the "Input" check box
selected. Use either a literal string or a
STRING variable.

Return Value
None

Comments
ScreenSelectObject is not supported on QuickPanel View/Control units.
Use this function in a PanelOpen script to automatically position your cursor
over the most commonly used input object.
The object specified in strObjectName can refer only to the following types of
graphical objects:
Arc Wedge Polygon
Bezier Curve Pie Wedge
Bitmap Rectangle
Button Round Rectangle
Circle/Ellipse Polyline
Line Text

ViewScript Example
In the following ViewScript example, ScreenSelectObject is used at the end of
a button script. It activates the function when the button is pressed and
places the cursor over the next button, which is 'Button2'.
ScreenSelectObject "Button2"

Active Scripting Example


This sample is the same as above, written in VBScript.
View.ScreenSelectObject "Button2"

See Also
ScreenSetCursorPos
View Scripting Functions Screen Navigation

ScreenSetCursorPos
Sets the cursor position to a specified location within a graphical panel.
Supported by: Windows PC targets only

Active Scripting syntax


View.ScreenSetCursorPos strPanelName, numXoffset, numYoffset

ViewScript syntax
ScreenSetCursorPos panName, numXoffset, numYoffset

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strPanelName panName The name of the panel you want the cursor
on.
numXoffset numXoffset Integer indicating the number of pixels to
the right from the left side of the panel.
numYoffset numYoffset Integer indicating the number of pixels
down from the top of the panel.

Return Value
0 : The window is not valid or not open.
1 : The window exists and is open.

Comments
You can use this command in PanelOpen script to automatically position your
cursor in the center of the panel.
ScreenSetCursorPos is not currently supported on QuickPanel View/Control.
When using this function in an Active Scripting language (such as VBScript),
names of all items and variables in parameters must be written as string
expressions.
ViewScript Examples
Example 1: The following ViewScript example places the cursor at position 85
pixels below the top of the panel 'MyPanel' and 205 pixels right of the left
side of the panel 'MyPanel'.
ScreenSetCursorPos MyPanel, 205, 85
Example 2: The following ViewScript example uses a script variable declared
as PanelIsOpen. This determines if the window 'MyPanel' is valid and open.
An IF statement can be used after the command to ensure the return value is
not zero (invalid or unopened). A negative numYOffset is used to place the
cursor above the window and uses a variable to provide value for the
numXOffset parameter.
PanelIsOpen := ScreenSetCursorPos MyPanel, HorizPosition, -113

Active Scripting Examples


These samples are the same as above, written in VBScript.
Example 1:
View.ScreenSetCursorPos "MyPanel", 205, 85
Example 2:
PanelIsOpen.Value = View.ScreenSetCursorPos ("MyPanel",
HorizPosition.Value, -113)

See Also
ScreenSelectObject
View Scripting Functions

Security script functions

Security functions provide access to user security and logging on and off of
an application. For more information on how security works in HMIs, see
Security for View Runtime: an Overview.
The following Security Functions are available:
Function Description
EditUserList Displays the Edit User List dialog box.
Logon Displays the Machine Edition Log On dialog box.
Logoff Logs off the current user.
View Scripting Functions Security

EditUserList
Opens the Edit User List dialog box.
Note: This script function is the only way to access the Edit User List dialog box.

Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.EditUserList

ViewScript syntax
EditUserList

Parameters
None.

Return Value
None.

Comments
This function is typically used in touch animation scripts.
For more information on configuring user accounts for View Runtime, see
Security for View Runtime: an Overview.
Warning: When viewing QuickPanel View/Control graphical panels remotely over the web
(see Remote Viewing of View Runtime), any dialog boxes that are opened because of actions
performed remotely on the HMI will not be closed on the QuickPanel View/Control display. This
will eventually cause the HMI application to fail. If you want to use a script function that opens a
dialog box on a QuickPanel View/Control target, it is highly recommended that you do not allow
users to operate the HMI remotely.

See Also
Logon, Logoff
View Scripting Functions Security

Logoff
Logs the current operator out of the HMI. Useful to log off users automatically
at a certain time of day or after a certain period of inactivity.
Note: This function is being deprecated and is not fully supported by remote views of graphical
panels (that is, when users view and use graphical panels over the web). In its place, we highly
recommend you use the "Log Off" Touch Animation action.

Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.Logoff

ViewScript syntax
Logoff

Return Value
None

Comments
If more than one user has logged on to the system, this function logs off only
the current user. Access control returns to the previously logged on user. This
lets a supervisor log on temporarily to perform some action, later returning
access to the original user.
For more information on configuring user accounts for View Runtime, see
Security for View Runtime: an Overview.

ViewScript Example
The following ViewScript example logs off the current user if the system has
not been used for ten minutes.
If (#IdleTime > 600)
Logoff
ENDIF

Active Scripting Example


This sample is the same as above, written in VBScript.
If (IdleTime.Value > 600) Then
View.Logoff
End If

See Also
Logon
View Scripting Functions Security

Logon
Use this command to display the Machine Edition Log On dialog box. This is
typically used in projects that hide the View menu bar, or where touch
screens are used instead of keyboards.
Note: This function is being deprecated and is not fully supported by remote views of graphical
panels (that is, when users view and use graphical panels over the web). In its place, we highly
recommend you use the "Log On" Touch Animation action.

Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.Logon [strUser, strPassword]

ViewScript syntax
Logon [strUser, strPassword]

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strUser strUser (Optional) String expression indicating the
user's name. This can be a literal string or
a STRING variable.
strPassword strPassword (Optional) String expression indicating the
user's password. This can be a literal string
or a string password.

Comments
After the operator logs on, the #AccessLevel system variable changes to
reflect the access rights (a number between 0 and 999) of the logged on
operator.
For more information on configuring user accounts for View Runtime, see
Security for View Runtime: an Overview.

Return Value
None
See Also
Logoff
View Scripting Functions

Serial Communication script functions

Serial communication functions allow your project to communicate to any


device attached to a serial port on your computer. By using these functions in
a script, you can open a port, send and receive data through a specified port,
and close a port (allowing access by other applications).
The following are serial communication functions covered in this section:
Function Description
ComPortClose Closes a serial port opened with the ComPortOpen function.
ComPortFlush Eliminates pending characters from the character buffers
(both receive and send).
ComPortGet Retrieves information from a serial port and saves it to a
STRING variable.
ComPortGetFile Retrieves information from a serial port and saves it to a file.
ComPortGetHex Retrieves information from a serial port in hexadecimal and
saves it to a STRING variable.
ComPortOpen Opens a port for use with ComPort functions.
ComPortPut Copies the Output string of ASCII characters to the serial
port.
ComPortPutFile Copies the contents of a file to the serial port.
ComPortPutHex Copies the Output string of hexadecimal characters to the
serial port.
Note: To access any of the communication port functions, excluding the ComPortClose function, it
is necessary to call the ComPortOpen function first (refer to the script sample).
View Scripting Functions Serial Communications

ComPortClose
Closes a serial port opened with the ComPortOpen function. Once a
communication port is closed, it must be reopened before it can be used
again.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.ComPortClose numPortNumber

ViewScript syntax
ComPortClose numPortNumber

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
numPortNumber numPortNumber Integer indicating the port to close. The
port must have been opened with the
ComPortOpen function.

Return Value

0 : The port was closed.


2 : The value in the numPortNumber parameter was within the 1 to 32 value
range.
4 : The port could not be closed. It was not successfully opened with the
ComPortOpen function.

Comments
Ensure you close any opened port before exiting View, or the port remains
unusable by other Windows applications.
Note: Opening and closing communication ports can impact performance, especially on QuickPanel
View/Control targets. Close and reopen ports only when absolutely required by your application.

ViewScript Example
The following ViewScript example closes COM1.
MyPortCloseStatus := ComPortClose 1

Active Scripting Example


This sample is the same as above, written in VBScript.
MyPortCloseStatus.Value = View.ComPortClose (1)

See Also
ComPortOpen
View Scripting Functions Serial Communications

ComPortFlush
Removes or "flushes" pending characters from the receive and send character
buffers. This function is typically used to reset a communications port after a
time-out error.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.ComPortFlush numPortNumber

ViewScript syntax
ComPortFlush numPortNumber

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
numPortNumber numPortNumber Integer indicating the port to flush. The
port must have been opened with the
ComPortOpen function.

Return Value
None

ViewScript Example
The following ViewScript example flushes out the characters in the buffers of
COM1.
ComPortFlush 1

Active Scripting Example


This sample is the same as above, written in VBScript.
View.ComPortFlush 1

See Also
ComPortOpen, ComPortClose
View Scripting Functions Serial Communications

ComPortGet
Retrieves ASCII data from a COM port. ComPortGet waits until MaxNumChars
characters are in the input buffer or a time-out period has passed, as
specified by TimeoutInMs.
If the time lapsed exceeds the time-out parameter, the amount of characters
retrieved can be less than the number specified. Use the return value to see
the number of characters returned.
Note: Use a time-out value of zero to return the characters in the buffer without waiting for enough
characters to satisfy the numMaxNumChars parameter.

Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.ComPortGet numPortNumber, strVarDestinationName,
numMaxNumChars, numTimeoutInMs

ViewScript syntax
ComPortGet numPortNumber, strvarDestination, numMaxNumChars,
numTimeoutInMs

Parameters (see Naming Conventions)


Active Scripting ViewScriptDescription
numPortNumber numPortNumber
Integer indicating the
communications port. The port
must have been opened with the
ComPortOpen function.
strVarDestinationName strvarDestination The Machine Edition STRING
variable to receive characters in
the port's input buffer.
numMaxNumChars numMaxNumChars Integer indicating the number of
characters to retrieve.
numTimeoutInMs numTimeoutInMs Integer indicating the maximum
time (in milliseconds) the function
waits for characters before
finishing.
Return Value
This function returns the number of ASCII characters read.

Comments
To get binary data from the port or get unprintable characters, use the
ComPortGetHex command.
When using this function in an Active Scripting language (such as VBScript),
names of all items and variables in parameters must be written as string
expressions. Also, strVarDestinationName cannot refer to a variable that is
locally defined in VBScript with a DIM statement.

ViewScript Examples
The following ViewScript examples demonstrate the use of both literal
(Example 1) and variable names (Example 2) used as parameters. You can
use either or both methods.
Example 1:
MyASCIIRetrieved := ComPortGet 1, ResultStringVar, 20, 500

Example 2:
MyASCIIRetrieved :=
ComPortGet PortNo, ResultStringVar, DesiredChars, WaitTime

Active Scripting Examples


These samples are the same as above, written in VBScript.
Example 1:
MyASCIIRetrieved.Value =
View.ComPortGet (1, ResultStringVar.Name, 20, 500)

Example 2:
MyASCIIRetrieved.Value = View.ComPortGet (PortNo.Value,
ResultStringVar.Name, DesiredChars.Value, WaitTime.Value)

See Also
ComPortPut, ComPortGetFile, ComPortGetHex, ComPortOpen
View Scripting Functions Serial Communications

ComPortGetFile
Retrieves ASCII characters from a communication port and saves them to a
file. This function returns when the maximum number of characters is
retrieved or the timeout period has expired, whichever comes first.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.ComPortGetFile numPortNumber, strFileName, numMaxNumChar,
numTimeoutInMs [, strStartCode] [, strStopCode]

ViewScript syntax
ComPortGetFile numPortNumber, strFileName, numMaxNumChar,
numTimeoutInMs [, strStartCode] [, strStopCode]

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
numPortNumber numPortNumber Integer indicating the port to read data
from. The port must have been opened
with the ComPortOpen function.
strFileName strFileName String indicating the name of the file in
which to save the acquired data.
numMaxNumChar numMaxNumChar Integer indicating the number of
characters to wait for before the function
returns. This parameter is limited by the
buffer size of the target that the script
runs on:
● For Windows PC targets,

numMaxNumChar can be from 1


through 65536 (64K).
● For QuickPanel View/Control units,
numMaxNumChar can be from 1
through 2048 (2K).
numTimeoutInMs numTimeoutInMs Integer indicating the maximum time (in
milliseconds) the function waits for
characters before returning.
strStartCode strStartCode (Optional) String expression containing a
series of decimal character(s) to be
matched against character(s) at the
beginning of the retrieved file. Use either
a literal string or a string variable. This
parameter is used to check that the file
was retrieved intact.
strStopCode strStopCode (Optional) String expression containing a
series of decimal character(s) to be
matched against character(s) at the end
of the retrieved file. Use either a literal
string or a string variable. This
parameter is used to check that the file
was retrieved intact.

Return Value

1 or greater: The number of characters read from communication port and


written to the specified file.
-1: The file could not be created for writing.
-2: No characters were read before the timeout
-3: The start and/or stop codes do not match the retrieved file.

Comments
If the file 'strFileName' exists, it will be overwritten.
Warning: If the file is bigger than the buffer for the target type, any characters beyond that
maximum are ignored. For example, you can only acquire up to 2048 characters of any file on
QuickPanel View/Control targets.

ViewScript Examples
The following ViewScript examples demonstrate the use of both literal
(Example 1) and variable names (Example 2) used as parameters. You can
use either or both methods.
Example 1:
MyPortGetFileStatus :=
ComPortGetFile 1, "c:\taylor\comport\retrieve.txt", 20, 500
Example 2:
MyPortGetFileStatus :=
ComPortGetFile PortNo, ResultFileName, DesiredChars, WaitTime

Active Scripting Examples


These samples are the same as above, written in VBScript.
Example 1:
MyPortGetFileStatus.Value = View.ComPortGetFile
(1, "c:\taylor\comport\retrieve.txt", 20, 500)
Example 2:
MyPortGetFileStatus.Value = View.ComPortGetFile (PortNo.Value,
ResultFileName.Name, DesiredChars.Value, WaitTime.Value)

See Also
ComPortOpen, ComPortPutFile, ComPortGet, ComPortGetHex
View Scripting Functions Serial Communications

ComPortGetHex
Retrieves bytes from the communication port as two digit hexadecimal
numbers.
When numMaxNumChars hexadecimal characters are in the input buffer, or a
time-out as specified by TimeoutInMs occurs, the characters are placed in the
strtagDestination string variable. If the time lapsed exceeds the time-out
parameter, the amount of characters can be less than the number specified.
Verify the return value to see the number of characters returned.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.ComPortGetHex numPortNumber, strVarDestinationName,
numMaxNumChars, numTimeoutInMs

ViewScript syntax
ComPortGetHex numPortNumber, strvarDestination, numMaxNumChars,
numTimeoutInMs

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
numPortNumber numPortNumber Integer indicating the port to read
data from. The port must have
been opened with the
ComPortOpen function.
strVarDestinationName strvarDestination The Machine Edition variable in
which characters read from the
input buffer are to be stored.
numMaxNumChars numMaxNumChars Integer indicating the number of
characters waited for before the
function returns.
numTimeoutInMs numTimeoutInMs Integer indicating the maximum
time (in milliseconds) the function
waits for characters before
returning.
Return Value
The number of hexadecimal characters read.

Comments
This function can be used to get non-ASCII characters from the port. For
example, if ComPortGet retrieves a carriage return or line feed character,
ComPortGet cannot store them correctly in a string varirable. If
ComPortGetHex is used, it retrieves "0d" and "0a", the hexadecimal
equivalents of the carriage return and line feed.
When using this function in an Active Scripting language (such as VBScript),
names of all items and variables in parameters must be written as string
expressions. Also, strVarDestinationName cannot be a variable that is locally
defined in VBScript with a DIM statement.

ViewScript Example
The following ViewScript example retrieves a maximum of 20 hexadecimal
characters (representing 10 bytes) from communication port #1 into
ResultStringTag for a maximum duration of 500 milliseconds.
MyHexReturned := ComPortGetHex 1, ResultStringVar, 20, 500

Active Scripting Example


This sample is the same as above, written in VBScript.
MyHexReturned.Value =
View.ComPortGetHex (1, ResultStringVar.Name, 20, 500)

See Also
ComPortPutHex, ComPortOpen, ComPortGet, ComPortGetFile
View Scripting Functions Serial Communications

ComPortOpen
Opens a port for use with other ComPort functions.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.ComPortOpen numPortNumber, strPortSettingsString

ViewScript syntax
ComPortOpen numPortNumber, strPortSettingsString

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
numPortNumber numPortNumber Integer indicating which port to
open. This number must not
conflict with any ports already in
use by the HMI application or any
other project.
strPortSettingsString strPortSettingsString String expression indicating comma-
separated port communication
settings. These settings should
appear in the following order:
Baud, Parity, Data bits, and
Stop bits, as in "4800,E,7,1". Use
either a literal string or STRING
variable.
● Baud: Can be 300, 600,

1200, 2400, 4800, 9600,


19200, 38400, 57600, or
115200
● Parity: Can be E, O (the letter
'O'), or N
● Data Bits: 7 or 8
● Stop Bits: 0, 1, or 2
Return Value
This function returns one of the following integer values, indicating the port
condition:
0: The port opened completed successfully.
1: Out of memory error.
2: Out of range error.
3: The port is in use.
4: The port could not be properly opened.
5: One or more of the communication settings were invalid.
6: The parity setting was invalid.
7: The data bits setting was invalid.
8: The stop bits setting was invalid.
9: Communications setup failed.

Comments
You must open a port before you use other serial communication port
functions.
Notes

● To change communication parameters, close the port using the ComPortClose function and
open it again using the new parameters.
● Opening and closing communication ports can impact performance, especially on QuickPanel
View/Control targets. Only close & reopen ports when absolutely required by your application.

ViewScript Example
The following ViewScript example opens communication port #1 using a baud
rate of 9600, no parity, eight data bits and one stop bit.
MyPortStatus := ComPortOpen 1,"9600,N,8,1"
Note: This function does not work if spaces are used between parameters.

Active Scripting Example


This sample is the same as above, written in VBScript.
MyPortStatus.Value = View.ComPortOpen (1,"9600,N,8,1")
Note: This function does not work if spaces are used between parameters.

See Also
ComPortClose
View Scripting Functions Serial Communications

ComPortPut
Copies the output string to the serial port and return immediately. Characters
are queued to write.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.ComPortPut numPortNumber, strOutputString

ViewScript syntax
ComPortPut numPortNumber, strOutputString

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
numPortNumber numPortNumber Integer indicating the port to which you
want to write data. The port must have
been opened with the ComPortOpen
function.
strOutputString strOutputString String expression indicating the actual
string to write. Use either a literal string or
STRING variable.

Return Value
The number of characters queued for output.

Comments
Use ComPortPutHex command instead when writing binary data equivalents
(printable characters such as carriage returns and line feeds, for example) to
the port.

ViewScript Example
The following ViewScript example sends the string "R100" into
communication port #1.
MyCharsQueued := ComPortPut 1, "R100"
Active Scripting Example
This sample is the same as above, written in VBScript.
MyCharsQueued.Value = View.ComPortPut (1, "R100")

See Also
ComPortClose, ComPortFlush, ComPortGet, ComPortOpen, ComPortPutFile,
ComPortPutHex
View Scripting Functions Serial Communications

ComPortPutFile
Sends the contents of a file to a specified communication port.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.ComPortPutFile numPortNumber, strFileName [,
strBOOLFlagWaitForXoff]

ViewScript syntax
ComPortPutFile numPortNumber, strFileName [, FlagWaitForXoff]

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
numPortNumber numPortNumber Integer indicating the port to which
you want to write data. The port
must have been opened with the
ComPortOpen function.
strFileName strFileName String indicating the name of the file
from where the data is to be
transferred.
strBOOLFlagWaitForXoff FlagWaitForXoff (Optional) If 1, the script function
waits for an XOFF character to be
sent from the communication port
as an acknowledgement. An XOFF
character is sent once the
communication port has received
the entire file.
If 0, the script does not wait for an
acknowledgement.

Return Value
This function returns -1 if the transmission was successful. Otherwise, it
returns the number of characters sent to the communication port from the
specified file.
Comments
The FlagWaitForXoff parameter is used with the XON/XOFF communications
protocol, in which the receiving device or computer uses special characters to
control the flow of data. When this flag is set, Machine Edition waits for the
XOFF character that is sent from the PLC (such as the Powermate-D) to
indicate the file transfer was successful.
The maximum size of the file you can send is limited by the buffer size for the
COM port. The buffer size varies with the target type.

● Windows PC targets: the buffer size is 65536 characters (64K).


● QuickPanel View/Control units: the buffer size is 2048 characters (2K).

Warning: If the file you want to send is bigger than the buffer size, characters beyond the size of
the buffer are ignored. For example, you can only send the first 2048 characters of a file on
QuickPanel View/Control targets.

ViewScript Example
The following ViewScript example sends the contents of the file "sendme.txt"
in the C:\data directory to communication port #1.
MyTransStatus := ComPortPutFile 1, "C:\Data\sendme.txt"

Active Scripting Example


This sample is the same as above, written in VBScript.
MyTransStatus.Value = View.ComPortPutFile (1, "C:\Data\sendme.txt")

See Also
ComPortOpen, ComPortGetFile, ComPortPut, ComPortPutHex
View Scripting Functions Serial Communications

ComPortPutHex
Use ComPortPutHex function to copy the output string of hexadecimal
characters to the communication port. The communication port queues the
characters to be sent out. Every two hexadecimal characters represents a
single byte that the communication port sends out.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.ComPortPutHex numPortNumber, strOutputString

ViewScript syntax
ComPortPutHex numPortNumber, strOutputString

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
numPortNumber numPortNumber Integer indicating the port to which you
want to write data. The port must have
been opened with the ComPortOpen
function.
strOutputString strOutputString String expression containing a series of
hexadecimal characters to send. This can
be a constant or STRING variable.

Return Value
1 : The port was open and characters were added to the queue.
0 : The port was not open, or write failed.

Comments
To send a non-ASCII character using this command, send the hexadecimal
equivalent. For example, to send a carriage return use the ComPortPutHex
command to send "0d" or to send a line feed send "0a".

ViewScript Example
The following ViewScript example outputs two bytes as the four hexadecimal
characters "D100" into communication port #1.
MyPortPutHexStatus := ComPortPutHex 1, "D100"

Active Scripting Example


This sample is the same as above, written in VBScript.
MyPortPutHexStatus.Value = View.ComPortPutHex (1, "D100")

See Also
ComPortGetHex
View Scripting Functions

SPC script functions

SPC script functions let you configure and manipulate statistical process
functions (SPCs).
Note: You must create an array (with SPCCreateArray) and add values to it (with SPCAddval)
before you use any of the other SPC functions.

Function Description
SPCAddval Adds a value to the array by copying the value of the value
parameter in to the next space in the array.
SPCClearArray Clears out all the values previously stored in the SPC array
pointed to by the ArrayPointer tag.
SPCCreateArray Creates an array of a designated size for storing data that
other SPC function use for calculation.
SPCDeleteArray Deletes an array of a designated size used for storing data
for other SPC functions.
SPCGetVal Returns the value stored in the array at a specified index
position.
SPCMax Returns the largest value stored in the array specified by
the numArrayID parameter.
SPCMean Returns the average of values stored in the array.
SPCVarianceMean Divides the array into smaller subgroups and calculates the
mean of each of these subgroups.
SPCMedian Arranges array values from lowest to greatest and locates
the position specified by the percent parameter.
SPCMin Returns the smallest value stored in the array specified by
the numArrayID parameter.
SPCRange Returns the range of values (minimum to maximum)
stored in the array specified by the numArrayID.
SPCRangeMean Divides the array into smaller subgroups, calculates the
mean of each group, and returns the range of these
subgroups.
SPCSaveToFile Saves the array into a file listing all the array elements and
their values.
SPCStdDev Returns the standard deviation of the array.
SPCStdDevMean Divides the array into smaller subgroups, calculates the
mean of each group, and returns the standard deviation of
the averages of the subgroups.
SPCSamples Returns the number of values entered into the array.
SPCSum Returns the sum of all the values in the array.
SPCVariance Returns the variance of values stored in the array specified
by the numArrayID parameter.
View Scripting Functions SPC

SPCAddval
Copies a value into the next open array position. This function is used to add
value(s) to the array you create using SPCCreateArray.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.SPCAddval numArrayID, numNewValue

ViewScript syntax
SPCAddval numArrayID, numNewValue

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
numArrayID numArrayID The pointer ID of the SPC Array in which
values are to be stored. This should be the
ID returned by the SPCCreateArray
function.
numNewValue numNewValue Numerical expression indicating the value
you want to be stored in the SPC array.

Return Value
None

Comments
If a value is added to an array and the array already has the maximum
number of values as configured on creation (when full), the new value
overwrites the oldest value in the array. In other words, if the array was
created to have a size of ten values the array remains to contain the last
value added and the previous nine values.
Character values cannot be added to SPC arrays. Doing so results in an
unpredictable CRC value being added to the array.

ViewScript Example
The first part of this ViewScript example creates an array storing the
temperature for each hour of the day. This command only runs on startup.
The second part of the example adds a temperature value to the array every
hour using a periodic script. Other SPC functions can be used to take the
statistical calculations, like the average temperature.
TemperatureArray := SPCCreateArray 24
SPCAddval TemperatureArray, Temperature

Active Scripting Example


This sample is the same as above, written in VBScript.
TemperatureArray.Value = View.SPCCreateArray (24)
View.SPCAddval TemperatureArray.Value, Temperature.Value

See Also
SPCClearArray, SPCCreateArray, SPCDeleteArray, SPCGetVal, SPCMax,
SPCMean, SPCVarianceMean, SPCMedian, SPCMin, SPCRange,
SPCRangeMean, SPCSamples, SPCSaveToFile, SPCStdDev, SPCStdDevMean,
SPCSum, SPCVariance
View Scripting Functions SPC

SPCClearArray
Clears out all values previously stored in the SPC array pointed to by an Array
Pointer variable, setting them to 0. Use this function to clear previous array
values.
Note: You must create an array and add values to it before using any SPC function. See
SPCCreateArray and SPCAddval.

Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.SPCClearArray numArrayID

ViewScript syntax
SPCClearArray numArrayID

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
numArrayID numArrayID The pointer ID of the SPC Array to clear.
This should be the ID returned by the
SPCCreateArray function.

Return Value
Returns 1 when successful and 0 if the values could not be cleared.

Comments
This function allows you to revise existing arrays, rather than having to
create new ones.

ViewScript Example
The first part of this ViewScript example creates an SPC array of size 'Size'
and places the ID number of the array in the variable 'IdVariable'. The second
part of the example clears this array by referencing its pointer stored in
'IdVariable'.
IdVariable := SPCCreateArray Size
MyClearArrayStatus := SPCClearArray IdVariable

Active Scripting Example


This sample is the same as above, written in VBScript.
IdVariable.Value = View.SPCCreateArray (Size.Value)
MyClearArrayStatus.Value = View.SPCClearArray (IdVariable.Value)

See Also
SPCAddval, SPCCreateArray, SPCDeleteArray, SPCGetVal, SPCMax, SPCMean,
SPCVarianceMean, SPCMedian, SPCMin, SPCRange, SPCRangeMean,
SPCSamples, SPCSaveToFile, SPCStdDev, SPCStdDevMean, SPCSum,
SPCVariance
View Scripting Functions SPC

SPCCreateArray
Creates an array for storing data for other SPC functions.
Note: You must add values to the array you create before you can use any SPC function. See
SPCAddval.

Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.SPCCreateArray numArraySize

ViewScript syntax
SPCCreateArray numArraySize

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
numArraySize numArraySize The number of elements or spaces for
samplers needed in the SPC array. This
must be between 2 and 16384.

Return Value
Returns an ID to the array that must be stored in an analog variable to
perform calculations on the array in other SPC functions. If you store the
array in a script variable, the array is lost at the end of the script. If the ID
number returned is -1, the array could not be created.
Note: The numArraySize parameter must be between 2 and 16384.

Comments
An array must be created and have values added to it using the SPCAddval
command before any other SPC functions can be used.

ViewScript Examples
The following ViewScript example creates an SPC array to include 15 value
positions and places the ID number of the array into the variable 'IdVariable'.
IdVariable := SPCCreateArray 15
The following ViewScript example creates an SPC array with the number of
spots for values equal to the value of the variable 'Size'.
IdVariable := SPCCreateArray Size

Active Scripting Examples


The following VBScript example creates an SPC array to include 15 value
positions and places the ID number of the array in the variable 'IdVariable'.
IdVariable.Value = View.SPCCreateArray (15)
The following VBScript example creates an SPC array with the number of
spots for values equal to the value of the variable 'Size'.
IdVariable.Value = View.SPCCreateArray (Size.Value)

See Also
SPCAddval, SPCClearArray, SPCDeleteArray, SPCGetVal, SPCMax, SPCMean,
SPCVarianceMean, SPCMedian, SPCMin, SPCRange, SPCRangeMean,
SPCSamples, SPCSaveToFile, SPCStdDev, SPCStdDevMean, SPCSum,
SPCVariance
View Scripting Functions SPC

SPCDeleteArray
Use SPCDeleteArray to delete an array that was created with SPCCreateArray
for storing data to be used with other SPC functions.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.SPCDeleteArray numArrayID

ViewScript syntax
SPCDeleteArray numArrayID

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
numArrayID numArrayID The pointer ID of the SPC Array that you
want to delete. This should be the ID
returned by the SPCCreateArray function.

Return Value
0 : The array was not deleted, or array may not exist.
1 : The array was deleted.

Comments
After use, an array must be deleted to free the memory resources being used
by the array.

ViewScript Example
The following ViewScript example deletes the SPC array with the ID number
contained in the variable 'MyArray'.
IdVariable := SPCDelete MyArray

Active Scripting Example


This sample is the same as above, written in VBScript.
IdVariable.Value = View.SPCDelete (MyArray.Value)

See Also
SPCAddval, SPCClearArray, SPCGetVal, SPCMax, SPCMean,
SPCVarianceMean, SPCMedian, SPCMin, SPCRange, SPCRangeMean,
SPCSamples, SPCSaveToFile, SPCStdDev, SPCStdDevMean, SPCSum,
SPCVariance
View Scripting Functions SPC

SPCGetVal
Returns the value stored in the array at a specified index position. This
function allows you to retrieve a specific value from an array.
Note: You must create an array and add values before you can use SPCGetVal. See
SPCCreateArray and SPCAddval.

Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.SPCGetVal numArrayID, numIndex

ViewScript syntax
SPCGetVal numArrayID, numIndex

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
numArrayID numArrayID The pointer ID of the SPC Array from
which you want to retrieve a value. This
should be an ID returned by the
SPCCreateArray function.
numIndex numIndex Integer indicating the index number of the
array for the value you want to retrieve
from the array.

Return Value
The value at index numIndex.

Comments
You can use this repeatedly. This is useful when comparing values in different
arrays.

ViewScript Example
The following ViewScript example retrieves the information from the fifth
value added to the array to the variable 'Postion5'.
Postion5 := SPCGetVal MyArray, 5

Active Scripting Example


This sample is the same as above, written in VBScript.
Postion5.Value = View.SPCGetVal (MyArray.Value, 5)

See Also
SPCAddval, SPCClearArray, SPCCreateArray, SPCDeleteArray, SPCMax,
SPCMean, SPCVarianceMean, SPCMedian, SPCMin, SPCRange,
SPCRangeMean, SPCSamples, SPCSaveToFile, SPCStdDev, SPCStdDevMean,
SPCSum, SPCVariance
View Scripting Functions SPC

SPCMax
Returns the largest value stored in the array specified by the numArrayID
parameter. Use this function to retrieve the greatest value in an array.
Note: You must create an array and add values before you can use SPCMax. See
SPCCreateArray and SPCAddval.

Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.SPCMax numArrayID

ViewScript syntax
SPCMax numArrayID

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
numArrayID numArrayID The pointer ID of the SPC Array whose
maximum value you want to retrieve. This
should be an ID returned by the
SPCCreateArray function.

Return Value
The greatest value.

ViewScript Example
The following ViewScript example retrieves the maximum value in the array
and place it in the variable 'Maximum'.
Maximum := SPCMax IdVariable

Active Scripting Example


This sample is the same as above, written in VBScript.
Maximum.Value = View.SPCMax (IdVariable.Value)

See Also
SPCAddval, SPCClearArray, SPCCreateArray, SPCDeleteArray, SPCGetVal,
SPCMean, SPCVarianceMean, SPCMedian, SPCMin, SPCRange,
SPCRangeMean, SPCSamples, SPCSaveToFile, SPCStdDev, SPCStdDevMean,
SPCSum, SPCVariance
View Scripting Functions SPC

SPCMean
Returns the average (mean) of all values stored in the array.
Note: You must create an array and add values before you can use SPCMean. See
SPCCreateArray and SPCAddval.

Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.SPCMean numArrayID

ViewScript syntax
SPCMean numArrayID

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
numArrayID numArrayID The pointer ID of the SPC Array whose
mean value you want to retrieve. This
should be an ID returned by the
SPCCreateArray function.

Return Value
Calculated value average of an array.

ViewScript Example
The following ViewScript example calculates the seven values and returns the
average. The seven values are shown and the value of 5 is placed in the
variable 'Average'.
MyArray = (2, 6, 5, 4, 8, 1, 9)
SPCMean = 5
Average := SPCMean MyArray

Active Scripting Example


This sample is the same as above, written in VBScript.
MyArray = (2, 6, 5, 4, 8, 1, 9)
View.SPCMean = 5
Average.Value = View.SPCMean (MyArray.Value)

See Also
SPCAddval, SPCClearArray, SPCCreateArray, SPCDeleteArray, SPCGetVal,
SPCMax, SPCVarianceMean, SPCMedian, SPCMin, SPCRange, SPCRangeMean,
SPCSamples, SPCSaveToFile, SPCStdDev, SPCStdDevMean, SPCSum,
SPCVariance
View Scripting Functions SPC

SPCMedian
Arranges values in an array from lowest to greatest, then locates the median
position specified by percent parameter.
Notes
You must create an array and add values before you can use SPCMedian. See SPCCreateArray
and SPCAddval.

Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.SPCMedian numArrayID, numPercent

ViewScript syntax
SPCMedian numArrayID, numPercent

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
numArrayID numArrayID The pointer ID of the SPC Array whose
median value you want to retrieve. This
should be an ID returned by the
SPCCreateArray function.
numPercent numPercent The specified median percentage position
(50% is the default).

Return Value
The value in the specified percent position.
If the value falls between two of the values in the array, the lower of the two
values will be returned as the median.

Comments
The median value of a set of values is a value such that numPercent% of the
values are less than the returned value, and (100-numPercent)% of the
values are greater than the returned value. Typically, numPercent is 50.
Setting numPercent to zero is equivalent to the SPCMin function. Setting
numPercent to 100 is equivalent to the SPCMax function. In an array with an
even number of values, using a median of 50% always rounds down.

ViewScript Examples
Example 1: In this ViewScript example, the values of 'MyArray' 2, 5, 3, 8, 1
are arranged from smallest to largest values, as displayed in 'Arranged
MyArray'. The 50% (which is 3) value of 3 is returned to the variable
'MidPoint'.
MyArray = (2, 5, 3, 8, 1)
Arranged MyArray = (1, 2, 3, 5, 8)
MidPoint := SPCMedian MyArray
Example 2: In this ViewScript example, the 25% value (which is 2) is
returned to the variable 'QuarterPoint'.
QuarterPoint := SPCMedian MyArray, 25

Active Scripting Examples


Example 1: In this VBScript example, the values of 'MyArray' 2, 5, 3, 8, 1 are
arranged from smallest to largest values, as displayed in 'Arranged MyArray'.
The 50% value (which is 3) is returned to the variable 'MidPoint'.
MyArray = (2, 5, 3, 8, 1)
Arranged MyArray = (1, 2, 3, 5, 8)
MidPoint.Value = View.SPCMedian (MyArray.Value)
Example 2: In this VBScript example, the 25% value (which is 2) is returned
to the variable 'QuarterPoint'.
QuarterPoint.Value = View.SPCMedian (MyArray.Value, 25)

See Also
SPCAddval, SPCClearArray, SPCCreateArray, SPCDeleteArray, SPCGetVal,
SPCMax, SPCMean, SPCVarianceMean, SPCMin, SPCRange, SPCRangeMean,
SPCSamples, SPCSaveToFile, SPCStdDev, SPCStdDevMean, SPCSum,
SPCVariance
View Scripting Functions SPC

SPCMin
Returns the smallest value stored in the array specified by the numArrayID
parameter.
Note: You must create an array and add values before you can use SPCMin. See
SPCCreateArray and SPCAddval.

Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.SPCMin numArrayID

ViewScript syntax
SPCMin numArrayID

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
numArrayID numArrayID The pointer ID of the SPC Array whose
minimum value you want to retrieve. This
should be an ID returned by the
SPCCreateArray function.

Return Value
Smallest value in an array.

ViewScript Example
This ViewScript example stores the minimum value in the array in the
variable 'Minimum'.
Minimum := SPCMin MyArray

Active Scripting Example


This sample is the same as above, written in VBScript.
Minimum.Value = View.SPCMin (MyArray.Value)

See Also
SPCAddval, SPCClearArray, SPCCreateArray, SPCDeleteArray, SPCGetVal,
SPCMax, SPCMean, SPCVarianceMean, SPCMedian, SPCRange,
SPCRangeMean, SPCSamples, SPCSaveToFile, SPCStdDev, SPCStdDevMean,
SPCSum, SPCVariance
View Scripting Functions SPC

SPCRange
Returns the range of values (arranged smallest to greatest) stored in the
array specified by the ArrayID parameter.
Note: You must create an array and add values before you can use SPCRange. See
SPCCreateArray and SPCAddval.

Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.SPCRange numArrayID

ViewScript syntax
SPCRange numArrayID

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
numArrayID numArrayID The pointer ID of the SPC Array whose
range of values you want to retrieve. This
should be an ID returned by the
SPCCreateArray function.

Return Value
The range (that is, the difference between the largest and smallest) of values
within the array. This is equivalent to SPCMax(numArrayID) -
SPCMin(numArrayID).

ViewScript Example
The following ViewScript example stores the maximum to minimum value in
the array in the variable 'Range'.
Range := SPCRange MyArray

Active Scripting Example


This sample is the same as above, written in VBScript.
Range.Value = View.SPCRange (MyArray.Value)
See Also
SPCAddval, SPCClearArray, SPCCreateArray, SPCDeleteArray, SPCGetVal,
SPCMax, SPCMean, SPCVarianceMean, SPCMedian, SPCMin, SPCRangeMean,
SPCSamples, SPCSaveToFile, SPCStdDev, SPCStdDevMean, SPCSum,
SPCVariance
View Scripting Functions SPC

SPCRangeMean
Divides the array into smaller subgroups. The size of the subgroups are
specified by the GroupSize parameter, calculating the range of each group
and returning the mean of these subgroups.
Note: You must create an array and add values before you can use SPCRangeMean function. See
SPCCreateArray and SPCAddval.

Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.SPCRangeMean numArrayID, numGroupSize

ViewScript syntax
SPCRangeMean numArrayID, numGroupSize

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
numArrayID numArrayID The pointer ID of the SPC Array that you
want to divide into subgroups. This should
be an ID returned by the SPCCreateArray
function.
numGroupSize numGroupSize Integer indicating the size of the subgroup
you want to specify.

Return Value
The range of the subgroups.

See Also
SPCAddval, SPCClearArray, SPCCreateArray, SPCDeleteArray, SPCGetVal,
SPCMax, SPCMean, SPCVarianceMean, SPCMedian, SPCMin, SPCRange,
SPCSamples, SPCSaveToFile, SPCStdDev, SPCStdDevMean, SPCSum,
SPCVariance
View Scripting Functions SPC

SPCSamples
Returns the number of values entered into the array.
Note: You must create an array and add values before you can use SPCSamples. See
SPCCreateArray and SPCAddval.

Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.SPCSamples numArrayID

ViewScript syntax
SPCSamples numArrayID

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
numArrayID numArrayID The pointer ID of the array whose number
of values you want to retrieve. This should
be an ID returned by the SPCCreateArray
function.

Return Value
Number of values currently entered into the array.

Comments
If you add more values than positions are available, the oldest values are
overwritten, and the maximum number of positions will be returned.

ViewScript Example
The following ViewScript example creates an array with ten positions and
stores the ID in the variable 'MyArray'. The values of 3, 5, 8 and 6 are added
to the array and the variable 'Number' receives a value of four.
MyArray := SPCCreateArray 10
SPCAddVal MyArray, 3
SPCAddVal MyArray, 5
SPCAddVal MyArray, 8
SPCAddVal MyArray, 6
Number := SPCSamples MyArray

Active Scripting Example


This sample is the same as above, written in VBScript.
MyArray.Value = View.SPCCreateArray (10)
View.SPCAddVal MyArray.Value, 3
View.SPCAddVal MyArray.Value, 5
View.SPCAddVal MyArray.Value, 8
View.SPCAddVal MyArray.Value, 6
Number.Value = View.SPCSamples (MyArray.Value)

See Also
SPCAddval, SPCClearArray, SPCCreateArray, SPCDeleteArray, SPCGetVal,
SPCMax, SPCMean, SPCVarianceMean, SPCMedian, SPCMin, SPCRange,
SPCRangeMean, SPCSaveToFile, SPCStdDev, SPCStdDevMean, SPCSum,
SPCVariance
View Scripting Functions SPC

SPCSaveToFile
Saves the array into a data file that lists all array positions and their values.
Note: You must create an array and add values before you can use SPCSaveToFile . See
SPCCreateArray and SPCAddval.

Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.SPCSaveToFile numArrayID, strFilename, strFileTitle

ViewScript syntax
SPCSaveToFile numArrayID, strFilename, strFileTitle

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
numArrayID numArrayID The pointer ID of the SPC Array that you
want to save. This should be an ID
returned by the SPCCreateArray function.
strFilename strFilename String expression indicating the name of
the file you want to save the array values
into. If a directory is not specified in the
path, the file is saved in the project
directory by default. Use either a literal
string or a STRING variable.
strFileTitle strFileTitle String expression indicating text to be
written to the first line of the saved file,
such as a title. Use either a literal string or
a STRING variable.

Return Value
None

See Also
SPCAddval, SPCClearArray, SPCCreateArray, SPCDeleteArray, SPCGetVal,
SPCMax, SPCMean, SPCVarianceMean, SPCMedian, SPCMin, SPCRange,
SPCRangeMean, SPCSamples, SPCStdDev, SPCStdDevMean, SPCSum,
SPCVariance
View Scripting Functions SPC

SPCStdDev
Use SPCStdDev to calculate the standard deviation (the square root of the
variance) of values within an array.
Note: You must create an array and add values before you can use SPCStdDev. See
SPCCreateArray and SPCAddval.

Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.SPCStdDev numArrayID

ViewScript syntax
SPCStdDev numArrayID

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
numArrayID numArrayID The pointer ID of the SPC Array whose
standard deviation you want to calculate.
This should be an ID returned by the
SPCCreateArray function.

Return Value
The standard deviation of the values in the array.

ViewScript Example
The following ViewScript example calculates the standard deviation of the
values in MyArray. The result is returned in the variable 'StdDev'.
StdDev := SPCStdDev MyArray

Active Scripting Example


This sample is the same as above, written in VBScript.
StdDev.Value = View.SPCStdDev (MyArray.Value)

See Also
SPCAddval, SPCClearArray, SPCCreateArray, SPCDeleteArray, SPCGetVal,
SPCMax, SPCMean, SPCVarianceMean, SPCMedian, SPCMin, SPCRange,
SPCRangeMean, SPCSamples, SPCSaveToFile, SPCStdDevMean, SPCSum,
SPCVariance
View Scripting Functions SPC

SPCStdDevMean
Divides an array into smaller subgroups. The size of the subgroups are
specified by the numGroupSize parameter, calculating the standard deviation
of each group and returning the mean of the subgroups.
Note: You must create an array and add values before you can use SPCStdDevMean. See
SPCCreateArray and SPCAddval.

Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.SPCStdDevMean numArrayID, numGroupSize

ViewScript syntax
SPCStdDevMean numArrayID, numGroupSize

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
numArrayID numArrayID The pointer ID of the SPC Array that you
want to divide. This should be an ID
returned by the SPCCreateArray function.
numGroupSize numGroupSize Integer indicating subgroup size.

Return Value
The standard deviation of the averages of the subgroups.

ViewScript Example
The following ViewScript example divides the 13 values in this array into
groups of three. The standard deviation of each of these subgroups are
calculated and the subgroup standard deviation is returned in the variable
'StdDevAverage'.
StdDevAverage := SPCVarianceMean MyArray, 4

Active Scripting Example


This sample is the same as above, written in VBScript.
StdDevAverage.Value = View.SPCStdDevMean (MyArray.Value, 4)

See Also
SPCAddval, SPCClearArray, SPCCreateArray, SPCDeleteArray, SPCGetVal,
SPCMax, SPCMean, SPCVarianceMean, SPCMedian, SPCMin, SPCRange,
SPCRangeMean, SPCSamples, SPCSaveToFile, SPCStdDev, SPCSum,
SPCVariance
View Scripting Functions SPC

SPCSum
Returns the sum of all values in an array. You can use this function to total
the values in an array.
Note: You must create an array and add values before you can use SPCSum. See
SPCCreateArray and SPCAddval.

Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.SPCSum numArrayID

ViewScript syntax
SPCSum numArrayID

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
numArrayID numArrayID The pointer ID of the SPC Array whose
sum you want to retrieve. This should be
an ID returned by the SPCCreateArray
function.

Return Value
The sum of all values in the array.

ViewScript Example
The following ViewScript example adds the seven values and return the total
of 35. The total value of 35 is placed in the variable 'Total'.
MyArray = (2, 6, 5, 4, 8, 1, 9)
SPCSum = 35
Total := SPCSum MyArray

Active Scripting Example


This sample is the same as above, written in VBScript.
MyArray = (2, 6, 5, 4, 8, 1, 9)
SPCSum = 35
Total.Value = View.SPCSum (MyArray.Value)

See Also
SPCAddval, SPCClearArray, SPCCreateArray, SPCDeleteArray, SPCGetVal,
SPCMax, SPCMean, SPCVarianceMean, SPCMedian, SPCMin, SPCRange,
SPCRangeMean, SPCSamples, SPCSaveToFile, SPCStdDev, SPCStdDevMean,
SPCVariance
View Scripting Functions SPC

SPCVariance
Returns the variance of values stored in the array specified by the
numArrayID parameter.
Note: You must create an array and add values before you can use SPCVariance. See
SPCCreateArray and SPCAddval.

Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.SPCVariance numArrayID

ViewScript syntax
SPCVariance numArrayID

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
numArrayID numArrayID The pointer ID of the SPC Array whose
variance you want to retrieve. This should
be an ID returned by the SPCCreateArray
function.

Return Value
Variance of the values within an array.

ViewScript Example
The following ViewScript example calculates the seven values and return the
variance. The seven values are shown and the value of 8.67 is placed in the
variable 'Variance'.
MyArray = (2, 6, 5, 4, 8, 1, 9)
Variance = 8.67
Variance := SPCVariance MyArray

Active Scripting Example


This sample is the same as above, written in VBScript.
MyArray = (2, 6, 5, 4, 8, 1, 9)
Variance = 8.67
Variance.Value = View.SPCVariance (MyArray.Value)

See Also
SPCAddval, SPCClearArray, SPCCreateArray, SPCDeleteArray, SPCGetVal,
SPCMax, SPCMean, SPCVarianceMean, SPCMedian, SPCMin, SPCRange,
SPCRangeMean, SPCSamples, SPCSaveToFile, SPCStdDev, SPCStdDevMean,
SPCSum
View Scripting Functions SPC

SPCVarianceMean
Divides an array into smaller subgroups. The size of the subgroups are
specified by the GroupSize parameter, calculating the variance of each group
and returning the mean of these subgroups.
Note: You must create an array and add values before you can use SPCVarianceMean. See
SPCCreateArray and SPCAddval.

Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.SPCVarianceMean numArrayID, numGroupSize

ViewScript syntax
SPCVarianceMean numArrayID, numGroupSize

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
numArrayID numArrayID The pointer ID of the SPC Array that you
want to divide. This should be an ID
returned by the SPCCreateArray function.
numGroupSize numGroupSize Integer indicating the size of the
subgroups.

Return Value
Calculated variance of subgroup averages.

ViewScript Example
The following ViewScript calculates the variance of each subgroup. The
average of these variances is returned in the variable 'StdVarAverage'.
StdVarAverage := SPCVarianceMean MyArray, 4

Active Scripting Example


This sample is the same as above, written in VBScript.
StdVarAverage.Value = View.SPCVarianceMean (MyArray.Value, 4)
See Also
SPCAddval, SPCClearArray, SPCCreateArray, SPCDeleteArray, SPCGetVal,
SPCMax, SPCMean, SPCMedian, SPCMin, SPCRange, SPCRangeMean,
SPCSamples, SPCSaveToFile, SPCStdDev, SPCStdDevMean, SPCSum,
SPCVariance
Structured Query Language: an Overview

(Not supported by QuickPanel targets.)

Structured Query Language (SQL) is a set of script functions that allow a


Machine Edition project to connect and communicate with ODBC compliant
databases, such as Oracle. By using SQL statements in scripts, you can
retrieve and manipulate data, create and delete tables, and otherwise
manipulate the structure of an SQL database.
SQL statements can be sorted into four general categories:

● Queries retrieve data from the tables in a database. Queries are also
called SELECT statements.
● Data-definition statements define the structure of the database. This
includes SQL statements that create, alter, or drop database objects
such as tables, views, and indexes.
● Data-manipulation statements change the data in a database by
inserting new data, updating existing data, or deleting data. The SQL
statements INSERT, UPDATE, and DELETE accomplish this.
● Data-control statements create new users or determine authority
levels and privileges on tables and views in the database.

The syntax of SQL statements is very easy to use. For example, the following
query selects the data in the columns 'NAME' and 'HEIGHT' from the table
'GUEST':
SELECT NAME, HEIGHT FROM GUEST;
SQL in View HMI applications

(Not supported by QuickPanel targets.)

In View, you can use SQL statements in a script to access a database for
which an Open Database Connectivity (ODBC) driver exists. You can read or
write data to any such database available to you on your network.
SQL also allows you to store information gathered with View, and then
transfer this information to your database. If you can access your database
on the network from your computer, so can the SQL DLL.
Note: The Unicode Datatypes in SQL are not supportedin View; more specifically NCHAR, NTEXT
and NVARCHAR.

Transferring data from fields in a database to variables defined in a Machine


Edition project is accomplished by prefixing variable names with >> and <<.

● >> is used when you are executing a statement that stores information
to a variable. This is useful for commands that retrieve information from
the database.
● << is used when you want a variable value to be inserted into the SQL
statement. The variable's value is substituted for the variable in the
statement and then the SQL statement is executed.

Examples
Example 1: Connect three fields from the table 'Cars' into three View
variables. The data from 'Color' will be passed to the STRING variable
'CarColor', the data from 'Type' will be passed to the variable 'CarType', and
the data from 'Serial Number' will be passed to the variable 'CarSerNumber'.
Note: Table fields containing spaces must be enclosed in square brackets.
SELECT Color, Type, [Serial Number]
INTO ('>>CarColor', >>CarType, >>CarSerNumber)
FROM CARS;
Example 2: Change the 'Color' field of the car whose 'number' field equals the
value of the 'CarNumber' variable.
UPDATE Cars
SET [Color] = '<<CarColor'
WHERE [Number] = <<CarNumber;
Notes

● When using '>>' and '<<' to identify variables, they must be View variable names, not
declared variables.
● If the variable is a STRING, you must enclose the '>>' or '<<' declaration within single
quotation marks, as in '<<CarColor' above. Do not use quotation marks for integer or
numerical variables.
SQL Error Reporting
(Not supported by QuickPanel targets.)

When using SQL statements in a script, it is often necessary to monitor the


success or failure of each statement. There are two error reporting methods
that you may find useful.

● Method One creates a pop-up window that displays the variables that
contain errors.
● Method Two requires more scripting and can only display a limited
amount of information, but it causes the script to pause where the error
occurs. This method must be used when multiple SQL statements are
used in one script.

Method One
The easiest way to report errors is to create a panel that displays the
variables that will contain errors. Configure a panel script to run when a panel
is opened. This script will issue the dbLastError function and pass the errors
into the variables displayed in the new panel. Whenever you want to check
for an error in a function, use an IF statement to check for the error
condition, and open the panel if the error is true.

ViewScript Example
The following ViewScript sample issues an SQL statement and brings up the
first record. SQLVar is an integer variable that is used to store the SQL
pointer. If either the dbFileSQL command or the dbFirstRecord command
fails, the panel is opened.
SQLVar := DBFileSQL "sqlfile.txt"
IF SQLVar = 0
PanelOpen SQLErrorPanel
ENDIF
DECLARE Success
Success := DBFirstRecord SQLVar
IF Success = 0
PanelOpen SQLErrorPanel
ENDIF

Active Scripting Example


This sample is the same as above, written in VBScript.
SQLVar.Value = View.DBFileSQL ("sqlfile.txt")
IF SQLVar.Value = 0 Then
View.PanelOpen "SQLErrorPanel"
End If
Dim Success
Success = View.DBFirstRecord (SQLVar.Value)
If Success = 0 Then
View.PanelOpen "SQLErrorPanel"
End If

Method Two
This method uses an IF statement like above, except that instead of opening
a window, it calls the dbLastError function and places the error message into
a STRING variable. The MESSAGE function is then used to display the
contents of the STRING variable.

ViewScript Example
The following ViewScript issues an SQL statement from a text file and
displays two messages if the function is unsuccessful: one to say which
function failed, and a second to display the error message retrieved from the
dbLastError function. 'ErrorCode' is the integer variable that receives the
error code returned by the ODBC driver, and 'ErrorString' is the STRING
variable that receives the driver error message.
SQLQuery := DBFileSQL "FindCar.txt"
IF SQLQuery = 0
Message "Query Failed", 16
DBLastError ErrorCode, ErrorString
Message ErrorString
ENDIF
DECLARE Success
Success := DBFirstRecord SQLQuery
IF Success = 0
Message "The specified car number was not found.", 16
DBLastError ErrorCode, ErrorString
Message ErrorString
ENDIF

Active Scripting Example


This sample is the same as above, written in VBScript.
SQLQuery.Value = View.DBFileSQL ("FindCar.txt")
If SQLQuery.Value = 0 Then
View.Message "Query Failed", 16
View.DBLastError ErrorCode.Name, ErrorString.Name
View.Message ErrorString.Value
End If
Dim Success
Success = View.DBFirstRecord (SQLQuery.Value)
If Success = 0 Then
View.Message "The specified car number was not found.", 16
View.DBLastError ErrorCode.Name, ErrorString.Name
View.Message ErrorString
End If
Note: The message box has limited space and may not be long enough to display an entire error
message. Some ODBC drivers give longer messages than others. If this happens, use the Variable
Inspector to view the entire message or switch to displaying the errors in a panel as described in
Method One, above.
Is Your ODBC Driver Set Up?
(Not supported by QuickPanel targets.)

Before using SQL in View, ensure that the 32-bit ODBC driver for your
database is already set up. To check your setup, run the ODBC program
found in the Control Panel in Windows. Check that all appropriate fields have
been filled in correctly. If you don't know what the correct settings are, check
your database documentation or contact your database administrator.
Note: ODBC functions are not supported on QuickPanel View/Control targets.
View Scripting Functions

SQL Script Functions

(Not supported by QuickPanel targets.)

Structured Query Language (SQL), is a language for managing an ODBC


compliant relational database system. Using SQL statements, you can
retrieve, update, and delete data, as well as create and modify tables. For
more information on SQL, see Structured Query Language: an Overview.
Note: SQL functions are not supported on QuickPanel View/Control targets.

In addition to SQL statements, the following SQL functions are available for
use within View scripts:

Function Description
dbConnect Open and attach the ODBC driver for the database to be
used.
dbDisconnect Disconnect and close the connection to the ODBC driver.
dbSQL Execute an SQL statement.
dbFileSQL Execute the SQL statement contained within the named
file.
dbEndSQL Clear the SQL statement and recover the memory that
was used by it.
dbGetRecordCount Get the number of records in a group of records.
dbFirstRecord Move the current record pointer to the first logical record
in a group of records.
dbGotoRecord Move the current record pointer to the named record in a
group of records.
dbLastError Fill an analog variable with the error code and a string
variable with the last error message that occurred.
dbLastRecord Move the current record pointer to the last logical record
in a group of records.
dbNextRecord Move the current record pointer to the next logical record
in a group of records.
dbPrevRecord Cause the current record pointer to move to the previous
logical record in a group of records.
View Scripting Functions SQL

dbConnect
Opens and "attaches" to the ODBC driver for the database to be used. The
ODBC driver is supplied by the user and is specific to the type of database.
This function must be called before any other SQL function is called.
Tip: The best place to use the dbConnect command is in an application script that runs on startup.

Supported by: Windows PC targets only

Active Scripting syntax


View.dbConnect strConnectParams

ViewScript syntax
dbConnect strConnectParams

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strConnectParams strConnectParams String indicating the name of the data
source that you want to connect to.
Return Value
Returns a 0 if the connection to the ODBC driver failed; otherwise the result
is non-zero.
Note: dbDisconnect must be called before this function can be called again.

ViewScript Examples
The following examples are written in ViewScript.
Example 1: dBase example.
declare _sqlVar
_sqlVar := dbConnect "Dbase Files"
if _sqlVar = 0
Message "Unable to connect to dBase ODBC driver"
endif
Example 2: Successful Connection example.
Always check for an error after using the dbConnect command, because
if this command fails, so will all others.
declare _Success
_Success := dbConnect "MS Access 2.0 Databases"
if _Success = 0
Message "Unable to Connect to Database Driver", 16
endif
Example 3: Oracle example.
declare _sqlVar
_sqlVar := dbConnect "QEOR7;UID=SYSTEM;PWD=SYSTEM"
if _sqlVar = 0
Message "Unable to connect to Oracle Server"
endif

Active Scripting Examples


The following examples are written in VBScript.
Example 1: dBase example.
Dim sqlVar
sqlVar = View.dbConnect ("Dbase Files")
If sqlVar = 0 Then
View.Message "Unable to connect to dBase ODBC driver"
End If
Example 2: Successful Connection example.
Always check for an error after using the dbConnect command, because
if this command fails, so will all others.
Dim Success
Success = View.dbConnect ("MS Access 2.0 Databases")
If Success = 0 Then
View.Message "Unable to Connect to Database Driver", 16
End If
Example 3: Oracle example.
Dim sqlVar
sqlVar = View.dbConnect ("QEOR7;UID=SYSTEM;PWD=SYSTEM")
If sqlVar = 0 Then
View.Message "Unable to connect to Oracle Server"
End If

See Also
dbDisconnect
View Scripting Functions SQL

dbDisconnect
Disconnects and closes the ODBC driver. Call this function when you are
finished accessing a specific database.
Tip: The best place to use the dbDisconnect command is in an application script that runs on
shutdown.

Supported by: Windows PC targets only

Active Scripting syntax


View.dbDisconnect

ViewScript syntax
dbDisconnect

Parameters
None.

Return Value
Returns 0 if it was unable to terminate the connection to the ODBC driver;
otherwise the result is non-zero.
Note: After this function is called, another SQL function cannot be called until dbConnect has been
called again.

ViewScript Example
This ViewScript example disconnects and closes the ODBC driver.
declare _sqlVar
_sqlVar := dbDisconnect
if _sqlVar = 0
Message "Unable to disconnect from ODBC driver"
endif

Active Scripting Example


This sample is the same as above, written in VBScript.
Dim sqlVar
sqlVar = View.dbDisconnect
if sqlVar = 0 Then
View.Message "Unable to disconnect from ODBC driver"
End If

See Also
dbConnect
View Scripting Functions SQL

dbEndSQL
Clears the SQL statement identified by numSQLHandle and recovers the
memory that was used by it. A dbEndSQL function should be executed for
every Select statement executed. dbEndSQL does not need to be run on non-
Select statements. These statements clear themselves from memory
automatically after executing.
Supported by: Windows PC targets only

Active Scripting syntax


View.dbEndSQL numSQLHandle

ViewScript syntax
dbEndSQL numSQLHandle

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
numSQLHandle numSQLHandle The SQL handle of the SQL result you want
to clear. This must be a handle acquired
from a call to dbSQL or dbFileSQL.

Return Value
Returns 0 if clearing the SQL statement failed; otherwise the result is non-
zero.
Note: Once dbEndSQL has been called, no other functions will work with the numSQLHandle just
cleared.

ViewScript Example
The following ViewScript example clears the query results in sqlVariable
(where sqlVariable was orignally set using a dbSql or dbFileSql statement)
and recovers the memory it used.
declare _sqlVar
_sqlVar := dbEndSQL sqlVariable
if _sqlVar = 0
Message "Unable to release SQL statement"
endif

Active Scripting Example


This sample is the same as above, written in VBScript.
Dim sqlVar
sqlVar = View.dbEndSQL (sqlVariable.Value)
If sqlVar = 0 Then
View.Message "Unable to release SQL statement"
End If

See Also
dbSQL, dbFileSQL
View Scripting Functions SQL

dbFileSQL
Executes the SQL statement contained within the named file. The file must be
a plain ASCII file (i.e., a standard text file) and contain one SQL statement.
The SQL statement must be entirely on the same line.
Note: Carriage returns can only be used at the beginning or end of a clause.

The return value of this script function is used to identify which set of records
an operation acts upon. This value may be used later by dbNextRecord,
dbLastRecord, etc.
Supported by: Windows PC targets only

Active Scripting syntax


View.dbFileSQL strFileName

ViewScript syntax
dbFileSQL strFileName
Parameters (see Naming Conventions)
Active Scripting ViewScript Description
strFileName strFileName String indicating the name of the file
containing the SQL database statement
that you want to execute. If a path name
is not included, the application looks in the
current project directory. The indicated file
should contain one SQL statement.

Return value
This function returns a float (referred to as the numSQLHandle) that can be
used in other SQL function calls—dbNextRecord, dbLastRecord, and so on. It
identifies the set of records an SQL operation acts upon. A return value of 0
indicates that the function failed.
Notes

● The statement in the file must be terminated with a semicolon (;).


● Results as used in the following discussion are the return values of the various SQL function
calls. This discussion does not apply to variables used within SQL statements.
● "Select" statements need to store their results in Machine Edition variables, not declared
variables, as they select groups of records to be stepped through. The statement will
continue until a separate script containing the dbEndSQL statement runs.
● Statements such as "insert, update, delete, and create table" can use declared variables to
store their results, as they typically are one-run statements and are ended automatically
after execution.

ViewScript Examples
The following examples are written in ViewScript.
Example 1: Execute the SQL statement contained within the file
SQLFILE1.TXT in the project directory.
sqlVariable1 := dbFileSQL "SQLFILE1.TXT"
Example 2: Execute the SQL statement contained within the file
SQLFILE2.TXT in the directory (C:\ORACLE\TAYLOR\SCRIPTS\).
sqlVariable2 := dbFileSQL "C:\ORACLE\TAYLOR\SCRIPTS\SQLFILE2.TXT"
See dbSQL for several examples of SQL statements. Any statement that can
be executed with a dbSQL call can be executed with a dbFileSQL call.

Active Scripting Examples


The following examples are written in VBScript.
Example 1: Execute the SQL statement contained within the file
SQLFILE1.TXT in the project directory.
sqlVariable1.Value = View.dbFileSQL ("SQLFILE1.TXT")
Example 2: Execute the SQL statement contained within the file
SQLFILE2.TXT in the directory (C:\ORACLE\TAYLOR\SCRIPTS\).
sqlVariable2.Value = View.dbFileSQL
("C:\ORACLE\TAYLOR\SCRIPTS\SQLFILE2.TXT")
See dbSQL for several examples of SQL statements. Any statement that can
be executed with a dbSQL call can be executed with a dbFileSQL call.

See Also
dbSQL
View Scripting Functions SQL

dbFirstRecord
Moves the current record pointer to the first logical record in the group of
records identified by the sqlIdentifier.
Supported by: Windows PC targets only

Active Scripting syntax


View.dbFirstRecord numSQLHandle

ViewScript syntax
dbFirstRecord numSQLHandle

Parameter (see Naming Conventions)


Active Scripting ViewScript Description
numSQLHandle numSQLHandle The SQL handle of the desired set of
records. This must be a handle acquired
from a call to dbSQL or dbFileSQL.

Return Value
Returns 0 if dbFirstRecord failed; otherwise the result is non-zero.
Note: dbFirstRecord will fail if the current selection contains no records or if the ODBC driver does
not support random record access.

ViewScript Example
The following ViewScript example moves the record pointer to the first logical
record in the group 'sqlVariable' (where sqlVariable was originally set using a
dbSql or dbFileSql statement).
declare _sqlVar
_sqlVar := dbFirstRecord sqlVariable
if _sqlVar = 0
Message "Unable to goto first record"
endif

Active Scripting Example


This sample is the same as above, written in VBScript.
Dim sqlVar
sqlVar = View.dbFirstRecord (sqlVariable.Value)
If sqlVar = 0 Then
View.Message "Unable to goto first record"
End If

See Also
dbLastRecord, dbNextRecord, dbPrevRecord, dbGotoRecord
View Scripting Functions SQL

dbGetRecordCount
Returns the number of records found in the group of records identified by the
numSQLHandle.
Supported by: Windows PC targets only

Active Scripting syntax


View.dbGetRecordCount numSQLHandle

ViewScript syntax
dbGetRecordCount numSQLHandle

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
numSQLHandle numSQLHandle The SQL handle of the set of records you
want to count. This must be a handle
acquired from a call to dbSQL or
dbFileSQL.

Return Value
The number of records in a group of records.

ViewScript Example
The following ViewScript example counts the number of records in the group
'sqlVariable' (where sqlVariable was originally set using a dbSql or dbFileSql
statement).
declare _sqlCount
_sqlCount := dbGetRecordCount sqlVariable
if _sqlCount = 0
Message "No records found"
endif

Active Scripting Example


This sample is the same as above, written in VBScript.
Dim sqlCount
sqlCount = View.dbGetRecordCount (sqlVariable.Value)
If sqlCount = 0 Then
View.Message "No records found"
End If

See Also
dbGotoRecord, dbFirstRecord, dbLastRecord
View Scripting Functions SQL

dbGotoRecord
Moves the current record pointer to the named logical record in the group of
records identified by the numSQLHandle.
Supported by: Windows PC targets only

Active Scripting syntax


View.dbGotoRecord numSQLHandle, numRecordNumber

ViewScript syntax
dbGotoRecord numSQLHandle, numRecordNumber

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
numSQLHandle numSQLHandle The SQL handle of the set of records
in which you want to jump to the
indicated record number. This must be
a handle acquired from a call to dbSQL
or dbFileSQL.
numRecordNumber numRecordNumber The record number of the database
you want to go to.

Return Value
Returns 0 if dbGotoRecord failed; otherwise the result is non-zero.
Note: dbGotoRecord will fail if the current selection contains no records or if the ODBC driver does
not support random record access.

ViewScript Example
The following ViewScript example moves the record pointer to the named
logical record in the group 'sqlVariable' (where sqlVariable was originally set
using a dbSql or dbFileSql statement).
declare _sqlVar
_sqlVar := dbGotoRecord sqlVariable, 13
if _sqlVar = 0
Message "Unable to goto record"
endif

Active Scripting Example


This sample is the same as above, written in VBScript.
Dim sqlVar
sqlVar = View.dbGotoRecord (sqlVariable.Value, 13)
If sqlVar = 0 Then
View.Message "Unable to goto record"
End If

See Also
dbFirstRecord, dbLastRecord, dbNextRecord, dbPrevRecord
View Scripting Functions SQL

dbLastError
Fills numErrorCode with the SQL error code, and strErrorMessage with the
last SQL error message that occurred. dbLastError always fills these variables
with the last error results, even if no new error has occurred. To clear the
analog and string variables, update them from within the script.
Supported by: Windows PC targets only

Active Scripting syntax


View.dbLastError numvarErrorCode, strVarErrorMessageName

ViewScript syntax
dbLastError numvarErrorCode, strvarErrorMessage

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
numvarErrorCode numvarErrorCode A Machine Edition integer
variable that will be filled with
the last error code. If the value
of the error code is non-zero, an
error has occurred with the
ODBC driver. The code can be
zero and the message non-
blank for internal errors.
strVarErrorMessageName strvarErrorMessage A Machine Edition STRING
variable that will be filled with
the last error message. If not
error has occurred, the variable
is empty. Error messages can
be up to 128 characters in
length.

Return Value
This function returns 0 if the error code could not be retrieved. It returns a
non-zero value if no error occurred.
Note: The error buffer is reused for each error, so if another error occurs, the previous message is
overwritten.

Comments
When using this function in an Active Scripting language (such as vbScript),
names of all items and variables in parameters must be written as string
expressions. Also, numVarErrorCode and strVarErrorMessageName cannot be
a variable that is locally defined in VBScript with a DIM statement.

ViewScript Example
The following ViewScript example fills the variable 'ErrorCode' with the error
code and the variable 'ErrorMessage' with the last error message that
occurred.
'ErrorCode is an analog variable displayed in the ErrorWindow
'ErrorMessage is a string variable displayed in the ErrorWindow
declare _sqlVar
_sqlVar := dbSql "Select * from tank;"
if _sqlVar = 0
declare err
err := dbLastError ErrorCode, ErrorMessage
if err = 0
message "An error occured in dbLastError while trying to access
the last error message."
else
PanelOpen ErrorWindow
endif
endif

Active Scripting Example


This sample is the same as above, written in VBScript.
'ErrorCode is an analog variable displayed in the ErrorWindow
'ErrorMessage is a string variable displayed in the ErrorWindow
Dim sqlVar
sqlVar = View.dbSql ("Select * from tank;")
If sqlVar = 0 Then
Dim err
err = View.dbLastError (ErrorCode.Name, ErrorMessage.Name)
If err = 0 Then
View.Message "An error occured in dbLastError while trying to
access the last error message."
Else
View.PanelOpen "ErrorWindow"
End If
End If

See Also
dbLastRecord
View Scripting Functions SQL

dbLastRecord
Moves the current record pointer to the last logical record in the group of
records identified by the numSQLHandle.
Supported by: Windows PC targets only

Active Scripting syntax


View.dbLastRecord numSQLHandle

ViewScript syntax
dbLastRecord numSQLHandle

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
numSQLHandle numSQLHandle The SQL handle of the desired set of
records. This must be a handle acquired
from a call to dbSQL or dbFileSQL.

Return Value
Returns 0 if dbLastRecord failed; otherwise the result is non-zero.
Note: dbLastRecord will fail if the current selection contains no records or if the ODBC driver does
not support random record access.

ViewScript Example
The following ViewScript example moves the record pointer to the next last
record in the group 'sqlVariable' (where sqlVariable was originally set using a
dbSql or dbFileSql statement).
declare _sqlVar
_sqlVar := dbLastRecord sqlVariable
if _sqlVar = 0
Message "Unable to goto last record"
endif

Active Scripting Example


This sample is the same as above, written in VBScript.
Dim sqlVar
sqlVar = View.dbLastRecord (sqlVariable.Value)
If sqlVar = 0 Then
View.Message "Unable to goto last record"
End If

See Also
dbFirstRecord, dbNextRecord, dbPrevRecord, dbGotoRecord
View Scripting Functions SQL

dbNextRecord
Moves the current record pointer to the next logical record in the group of
records identified by the sqlIdentifier.
Supported by: Windows PC targets only

Active Scripting syntax


View.dbNextRecord numSQLHandle

ViewScript syntax
dbNextRecord numSQLHandle

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
numSQLHandle numSQLHandle The SQL handle of the desired set of
records. This must be a handle acquired
from a call to dbSQL or dbFileSQL.

Return Value
This function returns 0 if dbNextRecord failed; otherwise the result is non-
zero.
Note: dbNextRecord will fail if the current selection contains no records or, if currently pointing to
the last record.

ViewScript Example
The following ViewScript example moves the record pointer to the next logical
record in the group 'sqlVariable' (where sqlVariable was originally set using a
dbSql or dbFileSql statement).
declare _sqlVar
_sqlVar := dbNextRecord sqlVariable
if _sqlVar = 0
Message "Unable to goto next record"
endif

Active Scripting Example


This sample is the same as above, written in VBScript.
Dim sqlVar
sqlVar = View.dbNextRecord (sqlVariable.Value)
If sqlVar = 0 Then
View.Message "Unable to goto next record"
End If

See Also
dbFirstRecord, dbLastRecord, dbPrevRecord, dbGotoRecord
View Scripting Functions SQL

dbPrevRecord
Moves the current record pointer to the previous logical record in a group of
records identified by the numSQLHandle.
Supported by: Windows PC targets only

Active Scripting syntax


View.dbPrevRecord numSQLHandle

ViewScript syntax
dbPrevRecord numSQLHandle

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
numSQLHandle numSQLHandle The SQL handle of the desired set of
records. This must be a handle acquired
from a call to dbSQL or dbFileSQL.

Return Value
Returns 0 if dbPrevRecord failed; otherwise the result is non-zero.
Note: dbPrevRecord will fail if the current selection contains no records, if currently pointing to the
first record or, if the ODBC driver does not support random record access.

ViewScript Example
The following ViewScript example moves the record pointer to the previous
logical record in the group 'sqlVariable' (where sqlVariable was originally set
using a dbSql or dbFileSql statement).
declare _sqlVar
_sqlVar := dbPrevRecord sqlVariable
if _sqlVar = 0
Message "Unable to goto previous record"
endif

Active Scripting Example


This sample is the same as above, written in VBScript.
Dim sqlVar
sqlVar = View.dbPrevRecord (sqlVariable.Value)
If sqlVar = 0 Then
View.Message "Unable to goto previous record"
End If

See Also
dbFirstRecord, dbLastRecord, dbNextRecord, dbGotoRecord
View Scripting Functions SQL

dbSQL
Executes an SQL statement. It makes any variable replacements and returns
an identifier that is to be used by other statements to access the records
selected by the SQL statement. Typically, the return value is stored in a
variable so that it can be used in other scripts.
Supported by: Windows PC targets only

Active Scripting syntax


View.dbSQL strSQLStatement

ViewScript syntax
dbSQL strSQLStatement

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strSQLStatement strSQLStatement A standard SQL database statement
ending with a semicolon (;).

Return Value
Returns a float that is used in later function calls to identify the SQL
statement to which the call applies. A return value of 0 indicates that the
function failed.
The result is used to identify which set of records an operation acts upon.
This value may be used later by dbNextRecord, dbLastRecord, etc.
Notes

● Results as used in the following discussion are the return values of the various SQL function
calls. This discussion does not apply to variables used within SQL statements.
● Typically, "select" statements need to store their results in Machine Edition variables, not
declared variables, as they select groups of records to be stepped through. As well, the
statement may persist until some event occurs and a separate script containing the
dbEndSQL statement runs.
● "Select" statements need to store their results in Machine Edition variables, not declared
variables, as they select groups of records to be stepped through. The statement will
continue until a separate script containing the dbEndSQL statement runs.
● Statements such as "insert, update, delete, and create table" can use declared variables to
store their results, as they typically are one-run statements and are ended automatically
after execution.

Comments
Variables are not updated until a specific record is selected. Records are
selected by issuing the dbFirstRecord, dbPrevRecord, dbNextRecord,
dbLastRecord, or dbGotoRecord script function.

ViewScript Examples
The following examples are written in ViewScript.
Example 1: Select all of the records from the 'tankread' database, assign
column 'temp' to the variable 'temperature', and assign column 'date' to the
variable 'date'. Note the use of the INTO clause to accomplish this. This
SELECT statement, like standard SQL, does not immediately load
'temperature' and 'date'. Variables are not updated until a specific record is
selected. Records are selected by issuing dbNextRecord, dbLastRecord, etc.
functions. This type of "SELECT ... INTO ..." statement provides a one-way
link between View and the database. Changing the position in the database
updates the variables, but changing the variables does not update the
database. To update the database use an "UPDATE ..." SQL statement.
sqlVariable2:= dbSQL "select temp, date INTO (>>temperature, >>date)
from tankread;"
Example 2: Add a new record to 'tankread'. The columns 'temp' and 'date'
are updated with the current values in the variables 'temperature' and 'date'
respectively. The addition and updates occur immediately. Issuing a
dbNextRecord, dbLastRecord, etc. command, after an INSERT function, has
no effect.
sqlVariable3 := dbSQL "INSERT INTO tankread (temp, date) values (
<<temperature, <<date);"
Example 3: Set the 'temp' column to 0 and the 'date' column to the value in
the variable 'date', for all records that 'date' is equal to "02/29/1995". This
type of function updates all the records with the same values. It does not
reload the variables for each record.
sqlVariable4 := dbSQL "UPDATE tankread SET (temp = 0, date = <<date)
where date = '02/29/1995';"
Example 4: Delete all records in 'tankread' where the value in the 'date'
column is "02/29/1995".
sqlVariable5 := dbSQL "DELETE FROM tankread WHERE date =
'02/29/1995';"
Example 5: Create a table using the SQL CREATE TABLE function. If an error
occurs, open the panel 'ErrorWindow'.
Note: The CREATE TABLE function and column formats differ for each database type. Please
consult the SQL manual for your database type.
sqlVariable6 := dbSQL "CREATE TABLE tankread (temp number(5,2), date
not null);"
if sqlVariable6 = 0
PanelOpen ErrorWindow
endif
Example 6: Error handling in this case is accomplished by having a separate
panel for displaying error messages and codes. When an error is detected,
(all SQL functions return 0 to indicate an error) the ErrorWindow is opened
and its 'On Panel Open' script is run. This loads two variables containing
information about the last error that occurred. These are displayed in the
ErrorWindow. This is just one way to handle SQL errors.
declare _err
_err := dbLastError errCodeVariable, errMsgVariable
if _err = 0
Message "Unable to access last error from dbLastError"
endif
Note: You'll notice that the examples use different variable names. This is a good practice as
ASSIGNING A NEW SQL STATEMENT TO A PREVIOUSLY ASSIGNED VARIABLE WILL NOT
REMOVE THE OLD SQL STATEMENT. This means system resources will not be released. Be
sure to issue a dbEndSQL before reusing a variable.

Active Scripting Examples


These samples are the same as above, written in VBScript.
Example 1: Select all of the records from the 'tankread' database, assign
column 'temp' to the variable 'temperature', and assign column 'date' to the
variable 'date'. Note the use of the INTO clause to accomplish this. This
SELECT statement, like standard SQL, does not immediately load
'temperature' and 'date'. Variables are not updated until a specific record is
selected. Records are selected by issuing dbNextRecord, dbLastRecord, etc.
functions. This type of "SELECT ... INTO ..." statement provides a one-way
link between View and the database. Changing the position in the database
updates the variables, but changing the variables does not update the
database. To update the database use an "UPDATE ..." SQL statement.
sqlVariable2.Value = View.dbSQL ("select temp, date INTO
(>>temperature, >>date) from tankread;")
Example 2: Add a new record to 'tankread'. The columns 'temp' and 'date'
are updated with the current values in the variables 'temperature' and 'date'
respectively. The addition and updates occur immediately. Issuing a
dbNextRecord, dbLastRecord, etc. command, after an INSERT function, has
no effect.
sqlVariable3.Value = View.dbSQL ("INSERT INTO tankread (temp, date)
values ( <<temperature, <<date);")
Example 3: Set the 'temp' column to 0 and the 'date' column to the value in
the variable 'date', for all records that 'date' is equal to "02/29/1995". This
type of function updates all the records with the same values. It does not
reload the variables for each record.
sqlVariable4.Value = View.dbSQL ("UPDATE tankread SET (temp = 0,
date = <<date) where date = '02/29/1995';")
Example 4: Delete all records in 'tankread' where the value in the 'date'
column is "02/29/1995".
sqlVariable5.Value = View.dbSQL ("DELETE FROM tankread WHERE date =
'02/29/1995';")
Example 5: Create a table using the SQL CREATE TABLE function. If an error
occurs, open the panel 'ErrorWindow'.
Note: The CREATE TABLE function and column formats differ for each database type. Please
consult the SQL manual for your database type.
sqlVariable6.Value = dbSQL ("CREATE TABLE tankread (temp
number(5,2), date not null);")
If sqlVariable6.Value = 0 Then
View.PanelOpen "ErrorWindow"
End If
Example 6: Error handling in this case is accomplished by having a separate
panel for displaying error messages and codes. When an error is detected,
(all SQL functions return 0 to indicate an error) the ErrorWindow is opened
and its 'On Panel Open' script is run. This loads two variables containing
information about the last error that occurred. These are displayed in the
ErrorWindow. This is just one way to handle SQL errors.
Dim err
err = View.dbLastError (errCodeVariable.Name, errMsgVariable.Name)
If err = 0 Then
View.Message "Unable to access last error from dbLastError"
End If
Note: You'll notice that the examples use different variable names. This is a good practice as
ASSIGNING A NEW SQL STATEMENT TO A PREVIOUSLY ASSIGNED VARIABLE WILL NOT
REMOVE THE OLD SQL STATEMENT. This means system resources will not be released. Be
sure to issue a dbEndSQL before reusing a variable.

See Also
dbLastError, dbEndSQL
SQL Statements

CREATE TABLE Statement


Use the CREATE TABLE statement to create a new table in a database.

Syntax
Square brackets ([]) indicate an optional parameter, and a pipe (|)
represents "or".
CREATE TABLE table (field1 type [(size)] [index1] [, field2 type
[(size)] [index2] [, ...]] [, multifieldindex [, ...]]);

Arguments

Argument Description
table The name of the table to be created.
field1, field2 The name of the field or fields to be created in the new table.
At least one field must be created.
type The data type of the field in the new table.
size The field size in characters (text fields only).
index1, index2 A CONSTRAINT clause defining a single-field index.
multifieldindex A CONSTRAINT clause defining a multiple-field index.

Example
Create a table called 'Cars', with three fields: one text field and two integer
fields.
CREATE TABLE [Cars] ([Serial Number] TEXT, [Number] INTEGER, [Color]
INTEGER);
Tip: It is often easier to do this in the database program if it is not an operation done on a regular
basis.

See Also
SELECT Statement, INSERT Statement , UPDATE Statement, DELETE
Statement, DROP Statement
SQL Statements

DELETE Statement
Use the DELETE statement to delete one or more records from a table.
Note: The syntax and examples are written as if they are commands in a text file being used by
the DBFileSQL command. So, to use them in a DBSQL command, you would type it as the DBSQL
function's parameter: all on one line and in quotes.

Syntax
Square brackets ([]) indicate an optional parameter, and a pipe (|)
represents "or".
DELETE [table.*]
FROM tableexpression
WHERE criteria;
Arguments

Argument Description
table The optional name of the table from which records will be
deleted.
tableexpression The name of the table or tables from which records will be
deleted. This argument can be a single table name or a
compound resulting from a JOIN or subquery.
criteria An expression that determines which records to delete.
Note: If you have issued a SELECT statement on the database before using the DELETE
command, the changes made to the records will not been seen in the selected records. A select
statement takes a "picture" of the database at the time the command is issued, it is not a direct link
to the database. (This is done so that other users can use the database at the same time.)
Therefore, after issuing an DELETE statement, you will have to end the SELECT statement and
reissue it to see the changes that the DELETE statement made to the database.

Example
Delete any records where the table field Number is less than or equal to the
value in the View variable 'CarNumber'.
DELETE
FROM Cars
WHERE [Number] <= (<<CarNumber);

See Also
SELECT Statement, INSERT Statement , UPDATE Statement, CREATETABLE
Statement, DROP Statement
SQL Statements

DROP Statement
Use the DROP statement to delete an existing table from a database or to
delete an existing index from a table.

Syntax
DROP TABLE table;
or
DROP INDEX index ON table;

Arguments

Argument Description
table The name of the table to be deleted or the table from which an
index will be deleted.
index The name of the index to be deleted from the table.

Example
Delete the Cars table from the database:
DROP TABLE Cars
Tip: Like creating tables, it is often easier to accomplish in the database program if it is not an
operation done on a regular basis.

See Also
SELECT Statement, INSERT Statement , UPDATE Statement, DELETE
Statement, CREATE TABLE Statement
SQL Statements

INSERT Statement
Use the INSERT statement to insert new records into a database table.
Note: The syntax and examples are written as if they are commands in a text file being used by
the DBFileSQL command. So, to use them in a DBSQL command, you would type it as the DBSQL
function's parameter: all on one line and in quotes.

Syntax
Square brackets ([]) indicate an optional parameter, and a pipe (|)
represents "or".
INSERT INTO target [(field1[, field2[, ...]])]
VALUES (value1[, value2[, ...]);

Arguments

Argument Description
target The name of the table to append records to.
field1, field2 For a multiple-record append query, these are the names of
the fields to be appended. For a single-record query, these are
the names of fields to which you want to append specific
values in a single new record.
value1, value2 The values to insert into the specific fields of the new record.
Each value will be inserted into the field that corresponds to
its position in the list; value1 will be inserted into field1 of the
new record, value2 into field2, and so on. For a constant
value, you must enclose each value in single quotation marks
(' ') and separate pairs of values with a comma. If inserting
the value from an View variable, use the variablename with
<< in front of it to indicate that the value is being extracted
from View.
Note: If you have issued a SELECT statement on the database before using the INSERT
command, the new record will not been seen in the selected records. A select statement takes a
"picture" of the database at the time the command is issued, it is not a direct link to the database.
(This is done so that other users can use the database at the same time.) To see the changes that
the INSERT command made to the database, end the SELECT statement and reissue it .

Example
This example inserts the values of four View variables as new records in the
table. It assumes that CarColor is a STRING variable and that CarType,
CarSerNumber, and CarPaintNumber are numerical.
INSERT INTO Cars (Number, Type, Color, [Serial Number])
VALUES (<<CarNumber, <<CarType, '<<CarColor', <<CarSerNumber);
Note: The syntax and examples are written as if they are commands in a text file being used by
the DBFileSQL command. So, to use them in a DBSQL command, you would type it as the DBSQL
command's parameter: all on one line and in quotes.

See Also
SELECT Statement, UPDATE Statement, DELETE Statement, CREATE TABLE
Statement, DROP Statement
SQL Statements

SELECT Statement
Use the SELECT statement to retrieve data.
Note: The syntax and examples are written as if they are commands in a text file being used by
the DBFileSQL command. So, to use them in a DBSQL command, you would type it as the DBSQL
function's parameter: all on one line and in quotes.

Syntax
Square brackets ([]) indicate an optional parameter, and a pipe (|)
represents "or".
SELECT [predicate] ( * | table.* | [table.]field1 [,
[table.]field2.[, ...]])
[AS alias1 [, alias2 [, ...]]]
INTO (>>variable1[[[, >>variable2], >>variable3], ...])
FROM tableexpression [, ...] [IN externaldatabase]
[WHERE... ]
[GROUP BY... ]
[HAVING... ]
[ORDER BY... ]
[WITH OWNERACCESS OPTION];

Arguments

Argument Description
predicate One of the following predicates: ALL, DISTINCT,
DISTINCTROW, or TOP. You use the predicate to restrict
the number of records returned.
table The name of the table from which records are selected.
field1, field2 The names of the fields to retrieve data from. If you
include more than one field, they will be retrieved in the
order listed.
alias1, alias2 The column names to use in displaying the retrieved data
in Datasheet view.
variable1, variable2 The View variable names you want the field data inserted
into, in the same order as the field names (so the data
from field1 will be inserted into the 'variable1' View
variable), to a maximum of 64 variables. If variablex is a
string variable, the '>>variablex' declaration must be
enclosed within single quotes.
tableexpression The name of the table or tables containing the data you
want to retrieve.
externaldatabase The name of the database containing the tables in
tableexpression, if not in the database you are currently
connected to.
Notes

● Data is not actually placed into a variable until a record has been specified using one of five
record selecting functions (DBNextRecord, DBPrevRecord, DBGotoRecord, DBLastRecord,
and the DBFirstRecord).
● When the data that is retrieved by the select statement contains more than one record, the
record data that the Machine Edition variables contain can be changed using the
DBNextRecord, DBPrevRecord, DBGotoRecord, DBLastRecord, and the DBFirstRecord
commands. Use the DBEndSQL function when you are done so that the records that have
been selected are freed.
● The maximum number of variables that values can be stored in is 64.

Examples
Example 1: The following statement connects three fields from the Access
table called 'Cars' into three View variables. The data from Color will be put
into the variable 'CarColor', the data from Type will be put into the variable
'CarType', and the data from Serial Number will be put into the variable
'CarSerNumber'. It assumes that CarColor is a STRING variable and the
CarType, CarSerNumber, and CarPaintNumber are numerical. Note that table
fields that contain spaces must be put in square brackets.
SELECT Color, Type, [Serial Number]
INTO ('>>CarColor', >>CarType, >>CarSerNumber)
FROM CARS;
Note: For help using the >> and << prefixes, see SQL in View.

Example 2: The following statement does the same as the above statement,
except that it only gets the records when the field called 'Number' matches
the value of the View variable called 'CarNumber'.
SELECT Color, Type, [Serial Number]
INTO ('>>CarColor', >>CarType, >>CarSerNumber)
FROM CARS
WHERE (Number = (<<CarNumber));
Note: For help using the >> and << prefixes, see SQL in View.

Example 3:The following statement does the same as the one above, except
that it also sorts the data. Sorting is done alphabetically when fields contain
text, and numerically when fields contain numbers.
SELECT Color, Type, [Serial Number]
INTO ('>>CarColor', >>CarType, >>CarSerNumber)
FROM CARS
WHERE (Number = (<<CarNumber))
ORDER BY (Type);
Note: For help using the >> and << prefixes, see SQL in View.

Example 4: If data is being retrieved from more than one table, the table
name must be used with the field name. The following example selects data
as above, from the Cars table, and also adds the 'Number' field from the
Paint table, which is related to the 'Cars' table by the 'Color' field.
SELECT Cars.[Color], Cars.[Type], Cars.[Serial Number],
Paint.[Number]
INTO ('>>CarColor', >>CarType, >>CarSerNumber, >>CarPaintNumber)
FROM Cars, Paint
WHERE (Number = (<<CarNumber))
ORDER BY (Type);
Notes

● The syntax and examples are written as if they are functions in a text file being used by the
DBFileSQL command. So, to use them in a DBSQL command, you would type it as the
DBSQL command's parameter: all on one line and in quotes.
● For help using the >> and << prefixes, see SQL in View.

See Also
INSERT Statement , UPDATE Statement, DELETE Statement, CREATETABLE
Statement, DROP Statement
SQL Statements

UPDATE Statement
Use the UPDATE statement to change values of fields in a database table.

Syntax
Square brackets ([]) indicate an optional parameter, and a pipe (|)
represents "or".
UPDATE table
SET newvalue
WHERE criteria;

Argument

Argument Description
table The name of the table whose data you want to modify.
newvalue An expression that determines the value to be inserted into a
particular field in the updated records.
criteria An expression that determines which records will be updated.
Only records that satisfy the expression are updated.
Note: If you have issued a SELECT statement to the database before using the UPDATE
command, changes made to the records will not been seen in the selected records. A select
statement takes a "picture" of the database at the time the command is issued; it is not a direct link
to the database. (This is done so that other users can use the database at the same time.) To see
the changes that the UPDATE command made to the database, end the SELECT statement and
reissue it .

Examples
Update the Color field for the repainted car whose Number field matches the
value of the CarNumber View variable. It assumes that CarColor is a STRING
variable and the CarNumber is numerical.
UPDATE Cars
SET [Color] = ('<<CarColor')
WHERE [Number] = (<<CarNumber);
Tip: To automatically update a particular field in a table, you can configure an application or
window script to run whenever a Machine Edition variable that contains that field changes. The
script would issue the UPDATE statement as in the example above.
Note: For help using the >> and << prefixes, see SQL in View.

See Also
SELECT Statement, INSERT Statement, DELETE Statement, CREATETABLE
Statement, DROP Statement
View Scripting Functions

String script functions

String functions allow you to perform various operations on STRING variable


values.
Note: These functions are designed for use in ViewScript. Most Active Scripting languages (such
as VBScript) have far more flexible mechanisms for handling strings. If you are using an Active
Scripting language, it is highly recommended that you use string handling functions native to that
language.

The following script functions perform operations on STRING values:


Function Description
CopyDateToString Converts date into string format.
CopyTimeToString Converts time into string format.
CopyUserToString Copies the currently logged on user name to a string.
StringCompare Compares two strings.
StringConCat Puts two strings together to create one.
StringCopy Copies a string into a STRING variable.
SubString Extracts a partial string from a string.
StringPos Returns the position of a sub-string from a string.
StringLength Returns the number of characters in a string.
StringToNum Converts a numeric string variable into an analog value.
StringFromNum Converts an analog variable or value into a STRING
variable.
ASCIIToDec Converts an ASCII string into a decimal value.
DecToASCII Converts a decimal value into an ASCII string.
HexStringFromNum Converts a numeric integer value into an ASCII string of
its hexadecimal representation.
View Scripting Functions String

ASCIIToDec
Converts an ASCII string into a decimal value.
Tip: This function is designed for use in ViewScript. Active Scripting languages (such as VBScript)
typically have native support for string manipulation, using methods and syntax that are far more
convenient.

Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.ASCIIToDec strSource [, numBytes]

ViewScript syntax
ASCIIToDec strSource [, numBytes]

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strSource strSource String containing the ASCII text that you
want converted.
numBytes numBytes (Optional) Indicates whether strSource is 1
or 2 bytes (characters). If not specified,
strSource is assumed to be 1 byte.

Return Value
The decimal value of an ASCII string.

Comments
When numBytes is 1, this function effectively returns the ASCII character
number of the first character in strSource.
When numBytes is 2, the numeric value treats the second character of
strSource as if it were the least significant byte. For example, given the string
"AB", the ASCII character "B" is treated as the most significant byte. "A"
(ASCII character 65) has a binary representation of 0100 0001. "B" (ASCII
character 66) has a binary representation of 0100 0010. The returned value
would then be 16961 (0100 0010 0100 0001).
ViewScript Examples
Example 1: This ViewScript example retrieves the ASCII character (such as
"A") from the 'barcode1' variable and converts it into a one-byte decimal
value (65).
MyASCIIString := ASCIIToDec barcode1, 1
Example 2: This ViewScript example retrieves the ASCII value from the
'barcode2' variable (such as "AB") and converts it into a two-byte decimal
value (16961).
MyASCIIString := ASCIIToDec barcode2, 2

Active Scripting Examples


Example 1: This VBScript example retrieves the ASCII character (such as "A")
from the 'barcode1' variable and converts it into a one-byte decimal value
(65).
MyASCIIString.Value = View.ASCIIToDec (barcode1.Value, 1)
Example 2: This VBScript example retrieves the ASCII value from the
'barcode2' variable (such as "AB") and converts it into a two-byte decimal
value (16961).
MyASCIIString.Value = View.ASCIIToDec (barcode2.Value, 2)
View Scripting Functions String

CopyDateToString
Copies the current date (and, optionally, the time) to a STRING variable.
When the numFormat parameter is not used, the current default format is
used.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.CopyDateToString strVarDestinationName [, numFormat]

ViewScript syntax
CopyDateToString strvarDestination [, numFormat]

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strVarDestinationName strvarDestination The Machine Edition STRING variable
in which the results are to be stored.
numFormat numFormat (Optional) Integer indicating the
format for the copied date. The
following values are supported:
0: MM/DD/YYYY
1: YYYY/MM/DD
2: YY/MM/DD
3: MM/DD/YY
4: YYYY-MM-DD HH:MM:SS
5: [d'YYYY-MM-DD
00:00:00.000000']
6: [dt'YYYY-MM-DD
HH:MM:SS:000000']
7: DD/MM/YY
8: DD/MM/YYYY
9: DD-MM-YYYY HH:MM:SS

Comments
When using this function in an Active Scripting language (such as VBScript),
names of all items and variables in parameters must be written as string
expressions. Also, strVarDestinationName cannot refer to a variable that is
locally defined in VBScript with a DIM statement.
The default numFormat depends on the installed Proficy Machine Edition
Language Pack:

● If no Language Pack is installed (that is, the language is English) or the


Polish Language Pack is installed, the default format is MM/DD/YYYY
(numFormat 0).
● If the German, Spanish, French, Italian, Czech, or Russian Language
Pack is installed, the default format is DD/MM/YYYY (numFormat 8).

Date format numFormat settings 5 and 6 are designed for database systems
that require it.

ViewScript Example
The following ViewScript example stores the full date and time into the
variable 'SaveDate'.
CopyDateToString SaveDate, 4

Active Scripting Example


This sample is the same as above, written in VBScript.
View.CopyDateToString SaveDate.Name, 4

See Also
CopyTimeToString, CopyUserToString
View Scripting Functions String

CopyTimeToString
Use CopyTimeToString to copy the current time into a STRING variable. The
format of the string is: hh:mm:ss.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.CopyTimeToString strVarDestinationName

ViewScript syntax
CopyTimeToString strvarDestination

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strVarDestinationName strvarDestination The Machine Edition STRING variable
in which to store the result.

Comments
This function is most useful when creating reports or downloading information
to a database that requires time stamp information.
When using this function in an Active Scripting language (such as VBScript),
names of all items and variables in parameters must be written as string
expressions. Also, strVarDestinationName cannot refer to a variable that is
locally defined in VBScript with a DIM statement.

ViewScript Example
The following ViewScript example stores the full date and time into the
variable 'SaveDate'.
CopyTimeToString SaveTime

Active Scripting Example


This sample is the same as above, written in VBScript.
View.CopyTimeToString SaveTime.Name
See Also
CopyDateToString, Logging Functions, CopyUserToString
View Scripting Functions String

CopyUserToString
Copies the name of the user currently logged on into a STRING variable. This
is useful when creating reports or database access scripts that require access
to the user name.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.CopyUserToString strVarDestinationName

ViewScript syntax
CopyUserToString strvarDestination

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strVarDestinationName strvarDestination The Machine Edition STRING variable
in which to store the result.

Return Value
None

Comments
When using this function in an Active Scripting language (such as VBScript),
names of all items and variables in parameters must be written as string
expressions. Also, strVarDestinationName cannot refer to a variable that is
locally defined in VBScript with a DIM statement.

ViewScript Example
The following ViewScript example stores the user name into the variable
'SaveUser'.
CopyUserToString SaveUser

Active Scripting Example


This sample is the same as above, written in VBScript.
View.CopyUserToString SaveUser.Name

See Also
CopyDateToString, CopyTimeToString
View Scripting Functions String

DecToASCII
Converts a decimal value into an ASCII string and passes the result to a
variable.
Tip: This function is designed for use in ViewScript. Active Scripting languages (such as VBScript)
typically have native support for string manipulation, using methods and syntax that are far more
convenient.

Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.DecToASCII strVarDestinationName, numDec [, numBytes]

ViewScript syntax
DecToASCII strvarDestination, numDec [, numBytes]

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strVarDestinationName strvarDestination Machine Edition STRING variable
containing the ASCII text that you
want converted.
numDec numDec The decimal value that you want
converted.
numBytes numBytes (Optional) Indicate whether numDec
specifies 1 or 2 bytes of ASCII text.
If not specified, it is assumed to
specify 1 byte.

Return Value
None

Comments
When using this function in an Active Scripting language (such as VBScript),
names of all items and variables in parameters must be written as string
expressions. Also, strVarDestinationName cannot refer to a variable that is
locally defined in VBScript with a DIM statement.
ViewScript Examples
Example 1: This ViewScript example converts the decimal value 65 into the
ASCII character "A" and stores the results in the 'barcode1' variable.
DecToASCII barcode1, 65, 1
Example 2: This ViewScript example converts the decimal value 16705 into
the ASCII characters "AA" and stores the results in the 'barcode2' variable.
DecToASCII barcode2, 16705, 2

Active Scripting Examples


Example 1: This VBScript example converts the decimal value 65 into the
ASCII character "A" and stores the results in the 'barcode1' variable.
View.DecToASCII barcode1.Name, 65, 1
Example 2: This VBScript example converts the decimal value 16705 into the
ASCII characters "AA" and stores the results in the 'barcode2' variable.
View.DecToASCII barcode2.Name, 16705, 2
View Scripting Functions String

HexStringFromNum
Converts an integer value into an ASCII string in hexadecimal format, passing
the result to a variable.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.HexStringFromNum strVarDestinationName, numSource [,
numBytes] [, numReversedOrder]

ViewScript syntax
HexStringFromNum strvarDestination, numSource [, numBytes] [,
reversedOrder]

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strVarDestinationName strvarDestination The Machine Edition STRING variable
in which to store the converted
result is to be stored.
numSource numSource The integer value that you want
converted. This can be an integer
variable or a numerical constant.
numBytes numBytes (Optional) Integer indicating the
number of bytes to include in the
string result, from 1 through 4. If
the resulting string is less than
numBytes, leading "0" characters
are added. If not specified,
numBytes is assumed to be 4.
Note: The converted string will use two ASCII
characters for each byte. For example, if the
number of specified bytes was 2, the decimal
value 26 would be converted as "001A".
numReversedOrder reversedOrder (Optional) Integer indicating one of
the following:

● If 0, a negative number, or if
reversedOrder is not specified,
the resulting string is a direct
hexadecimal representation of
the value.
● If a positive number, the
resulting string uses the Intel
"reversed order" format and
can be used as the
strOutputString parameter of
ComPortPutHex. For details,
see Comments below.

Return Value
This function returns one of the following integer values:
0: The conversion was not successful. This could be because numBytes
falls outside the valid range, or because numBytes was not large enough
to hold the resulting string.
1: The conversion was successful.

Comments
When generating a string in Intel "reversed order" format, the byte order is
reversed, with the least significant byte written first. For example, if the
hexadecimal string that would normally be produced was "0147D4CE",
setting reversedOrder to a positive number instead produces "CED44701".
Note that the digits within each byte stay in the same order.
When using this function in an Active Scripting language (such as VBScript),
names of all items and variables in parameters must be written as string
expressions. Also, strVarDestinationName cannot refer to a variable that is
locally defined in VBScript with a DIM statement.

ViewScript Examples
Example 1: This ViewScript example converts the integer value 15788 into
the "MyString1" string variable. MyString1 will then contain "00003DAC".
MyHexStringFromNumStatus := HexStringFromNum MyString1, 15788
Example 2: This ViewScript example converts the integer value 15788 into
the "MyString2" string variable, using only two bytes and in Intel format.
MyString2 will then contain "AC3D".
MyHexStringFromNumStatus := HexStringFromNum MyString2, 15788, 2, 1

Active Scripting Examples


Example 1: This VBScript example converts the integer value 15788 into the
"MyString1" string variable. MyString1 will then contain "00003DAC".
MyHexStringFromNumStatus.Value = View.HexStringFromNum
(MyString1.Name, 15788)
Example 2: This VBScript example converts the integer value 15788 into the
"MyString2" string variable, using only two bytes and in Intel format.
MyString2 will then contain "AC3D".
MyHexStringFromNumStatus.Value = View.HexStringFromNum
(MyString2.Name, 15788, 2, 1)
View Scripting Functions String

StringCompare
Compares two strings to see which comes before the other, alphabetically.
Tip: This function is designed for use in ViewScript. Active Scripting languages (such as VBScript)
typically have native support for string manipulation, using methods and syntax that are far more
convenient.

Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.StringCompare strString1, strString2 [, numCaseSensitive]

ViewScript syntax
StringCompare strString1, strString2 [, numCaseSensitive]

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strString1 strString1 String expression indicating the first
string to compare. Use either a literal
string or a STRING variable.
strString2 strString2 String expression indicating the second
string to compare. Use either a literal
string or a STRING variable.
numCaseSensitive numCaseSensitive (Optional) If 1, performs a case-
sensitive search. If any other value,
performs a non-case-sensitive search.
Default is not case sensitive.

Return Value
-1 : If String1 alphabetically comes before String2.
0 : If String1 is equivalent to String2.
1 : If String1 alphabetically comes after String2.

ViewScript Example
The following ViewScript example compares the string variable 'PartNum' to
the literal string 'TO3AX5' and stores the result value in the variable
'returnValue'.
returnValue := StringCompare PartNum, "TO3AX5"

Active Scripting Example


The following VBScript example compares the string variable 'PartNum' to the
literal string 'TO3AX5' and stores the result value in the variable
'returnValue'.
returnValue.Value = View.StringCompare (PartNum.Value, "TO3AX5")

See Also
SubString
View Scripting Functions String

StringConCat
Adds the contents of one STRING variable to another STRING variable.
StrSource is added onto the end of StrDestination and stored in
StrDestination.
Tip: This function is designed for use in ViewScript. Active Scripting languages (such as VBScript)
typically have native support for string manipulation, using methods and syntax that are far more
convenient.

Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.StringConCat strVarDestinationName, strSource

ViewScript syntax
StringConCat strDestination, strSource

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strVarDestinationName strDestination The Machine Edition STRING variable
with the first half of the string in the
concatenation. The concatenated value
will be stored in this variable.
strSource strSource String expression indicating the string
to append to the end of the current
value of the STRING variable indicated
by strVarDestinationName or
strDestination. This can be either a
literal string or a STRING variable.

Return Value
None

Comments
When using this function in an Active Scripting language (such as VBScript),
names of all items and variables in parameters must be written as string
expressions. Also, strVarDestinationName cannot refer to a variable that is
locally defined in VBScript with a DIM statement.

ViewScript Example
This ViewScript example combines two strings to create the word baseball.
The variable String1 contains 'base' and variable String2 contains 'ball'.
StringConCat String1, String2
'String1 becomes "baseball" and String2 remains "ball".

Active Scripting Example


This sample is the same as above, written in VBScript.
View.StringConCat String1.Name, String2.Value
'String1 becomes "baseball" and String2 remains "ball".

See Also
StringCopy, SubString
View Scripting Functions String

StringCopy
Copies the contents of one STRING variable onto another STRING variable.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.StringCopy strVarDestinationName, strSource

ViewScript syntax
StringCopy strDestination, strSource

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strVarDestinationName strDestination The Machine Edition STRING variable
into which you want to copy strSource.
strSource strSource String expression indicating the string
you want to copy into
strVarDestinationName or
strDestination. This can be either a
literal string or a STRING variable.

Return Value
None

Comments
When using this function in an Active Scripting language (such as VBScript),
names of all items and variables in parameters must be written as string
expressions. Also, strVarDestinationName cannot refer to a variable that is
locally defined in VBScript with a DIM statement.

ViewScript Examples
Example 1: This ViewScript example copies one of three different constant
strings to the variable 'ShiftName'.
if #CurrentTime.HR < 8
StringCopy ShiftName, "First Shift"
else
if #CurrentTime.HR < 16
StringCopy ShiftName, "Second Shift"
else
StringCopy ShiftName, "Third Shift"
endif
endif
Example 2: This ViewScript example copies the contents of the variable
'OldRecipe' into another variable 'NewRecipe'.
StringCopy NewRecipe, OldRecipe

Active Scripting Examples


Example 1: This VBScript example copies one of three different constant
strings to the variable 'ShiftName'.
If CurrentTime.Element("HR").Value < 8 Then
View.StringCopy ShiftName.Name, "First Shift"
Else
If CurrentTime.Element("HR").Value < 16 Then
View.StringCopy ShiftName.Name, "Second Shift"
Else
View.StringCopy ShiftName.Name, "Third Shift"
End If
End If
Example 2: This VBScript example copies the contents of the variable
'OldRecipe' into another variable 'NewRecipe'.
View.StringCopy NewRecipe.Name, OldRecipe.Value

See Also
StringConCat, SubString
View Scripting Functions String

StringLength
Returns the number of characters in a specified string.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.StringLength strString

ViewScript syntax
StringLength strString

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strString strString String expression of the string whose
length you want to retrieve.

Return Value
The number of characters in the string.

ViewScript Example
In the following ViewScript example, if the string variable, 'BarCodeStr' has
the value "ABCD-3456", then
LengthVar := StringLength BarCodeStr
would return the value 9 in 'LengthVar'.

Active Scripting Example


This sample is the same as above, written in VBScript.
LengthVar.Value = View.StringLength (BarCodeStr.Value)

See Also
StringPos, SubString, StringCopy, StringCompare
View Scripting Functions String

StringFromNum
Converts an analog (integer or real) variable or value into a STRING variable.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.StringFromNum strVarDestinationName, numSource [, numDigits,
numDecimals]

ViewScript syntax
StringFromNum strvarDestination, numSource [, numDigits,
numDecimals]

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strVarDestinationName strvarDestination The Machine Edition STRING variable
where the result is to be stored.
numSource numSource Integer or real expression indicating
the value to convert into a string.
This can be a variable or numerical
constant.
numDigits numDigits (Optional) Integer indicating the
minimum field width. The converted
string will have at least this number
of characters, wider if necessary. If
the converted string has fewer
characters than numDigits, the
string will be padded with spaces on
the left to make up the total.
Tip: This parameter can be useful when using
string concatenation to create formatted
strings to line up in columns in a listbox.
numDecimals numDecimals (Optional) Integer indicating the
number of decimal places to retain
in the new STRING variable.
Return Value
None

Comments
When using this function in an Active Scripting language (such as VBScript),
names of all items and variables in parameters must be written as string
expressions. Also, strVarDestinationName cannot refer to a variable that is
locally defined in VBScript with a DIM statement.

ViewScript Example
The following ViewScript example converts the floating point value
TankLevelValue into a string, storing the results in the variable TankLevelStr.
StringFromNum TankLevelStr, TankLevelValue, 4, 1

Active Scripting Example


This sample is the same as above, written in VBScript.
View.StringFromNum TankLevelStr.Name, TankLevelValue.Value, 4, 1

See Also
SubString, StringPos, StringToNum
View Scripting Functions String

StringPos
Returns the position of a sub-string from a string. This is useful when parsing
information from a longer string.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.StringPos strPatternString, strSearchString, numCaseSensitive

ViewScript syntax
StringPos strPatternString, strSearchString, numCaseSensitive

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strPatternString strPatternString String expression indicating the
substring that you want to locate. Use
either a literal string or a STRING
variable.
strSearchString strSearchString String expression indicating the string in
which to search for the substring. Use
either a literal string or a STRING
variable.
numCaseSensitive numCaseSensitive Indicates whether to perform a case-
sensitive or a non-case-sensitive search.
If 1, a case-sensitive search is
performed. If 0 (default), a non-case-
sensitive search is performed.

Return Value
The position of the first character of the sub-string.

Comments
This function is commonly used with SubString. StringPos locates and
retrieves the sub-string position within a string.
When using this function in an Active Scripting language (such as vbScript),
names of all items and variables in parameters must be written as string
expressions.

ViewScript Example
In the following ViewScript example, if the BarCodeStr has a value of 'ABCD-
5678' then:
MyPositionVariable := StringPos "5678", BarCodeStr, 1
stores 6 into Positionvariable.

Active Scripting Example


This sample is the same as above, written in VBScript.
MyPositionVariable.Value = View.StringPos ("5678",
BarCodeStr.Value, 1)

See Also
Substring, StringToNum, StringFromNum
View Scripting Functions String

StringToNum
Converts a numeric STRING variable into an analog value. The second
parameter allows you to specify the numerical format of the string.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.StringToNum strSource [, numMode]

ViewScript syntax
StringToNum strSource [, numMode]

Parameters (see Naming Conventions)


Active ViewScript Description
Scripting
strSource strSource The Machine Edition STRING variable with the
value you want to convert.
numMode numMode (Optional) Mode = 0 string contains a decimal
number (default value).
Mode = 1 string contains a hexadecimal number
(e.g., 11AB).
Mode = 2 string contains a two digit hexadecimal
number, represented as two byte characters in
Intel format (lobyte, hibyte).

Return Value
This function returns the numeric value of the string. This can be assigned to
a declared variable or variable.

Comments
If the string contains non-numeric characters only the numbers before the
first non-numeric character are converted (for example, 01.235C45 to
1.235).
If numMode is 2, only the first two characters of strSource are used. All other
digits are ignored.
ViewScript Examples
Example 1: This ViewScript example converts a string in the 'TankLevelStr'
variable (for example '00435.467') to the value 435.467 and places it into the
'TankLevelValue' analog variable.
TankLevelValue := StringToNum TankLevelStr
Example 2: This ViewScript example converts a hexadecimal string "A1" into
the decimal number 161 and places it into the 'TankLevelValue' analog
variable.
TankLevelValue := StringToNum "A1", 1
Example 3: This ViewScript example converts the first two digits of the string
in the 'TankeLevelStr' variable into a numerical value, treating it as a
hexadecimal number in Intel (little-endian) format. The result is placed into
the 'TankLevelValue' analog variable.
TankLevelValue := StringToNum TankLevelStr, 2

Active Scripting Examples


Example 1: This VBScript example converts a string in the 'TankLevelStr'
variable (for example '00435.467') to the value 435.467 and places it into the
'TankLevelValue' analog variable.
TankLevelValue.Value = View.StringToNum (TankLevelStr.Value)
Example 2: This VBScript example converts a hexadecimal string "A1" into
the decimal number 161 and places it into the 'TankLevelValue' analog
variable.
TankLevelValue.Value = View.StringToNum ("A1", 1)
Example 3: This VBScript example converts the first two digits of the string in
the 'TankeLevelStr' variable into a numerical value, treating it as a
hexadecimal number in Intel (little-endian) format. The result is placed into
the 'TankLevelValue' analog variable.
TankLevelValue.Value = View.StringToNum (TankLevelStr.Value, 2)

See Also
SubString, StringPos, StringFromNum
View Scripting Functions String

SubString
Extracts a sub-string from a string.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.SubString strVarDestinationName, strSource, numStartingAt,
numMaxCount

ViewScript syntax
SubString strVarDestination, strSource, numStartingAt, numMaxCount

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strVarDestinationName strVarDestination The Machine Edition STRING
variable in which to store the sub-
string.
strSource strSource String expression with the source
string from which the sub-string will
be retrieved. Use either a literal
string or a STRING variable.
numStartingAt numStartingAt Integer indicating the number of the
character where the sub-string
begins.
numMaxCount numMaxCount Integer indicating the number of
characters to extract (that is, the
maximum length of the sub-string).
If numMaxCount takes the sub-
string beyond the end of strSource,
the extra characters are ignored.

Return Value
None

Comments
To locate a sub-string's position, use the StringPos function.
When using this function in an Active Scripting language (such as VBScript),
names of all items and variables in parameters must be written as string
expressions. Also, strVarDestinationName cannot refer to a variable that is
locally defined in VBScript with a DIM statement.

ViewScript Examples
Variable 'BarCodeStr' has a value of 'ABCD-5678'.
Example 1: This ViewScript example stores ABCD into 'StringVar1'.
Substring StringVar1, BarCodeStr, 1, 4
Example 2: This ViewScript example stores 5678 into 'StringVar1'.
Substring StringVar1, BarCodeStr, 6, 4

Example 3: In this ViewScript example, InputString has the name of a model


(such as "WidgetPart M254". The example finds the part number following the
"M", up to 5 digits.
StartChar := StringPos "M", InputString
SubString strResult, InputString, StartChar, StartChar +5
PartNumber := StringtoNum strResult

Active Scripting Examples


Variable 'BarCodeStr' has a value of 'ABCD-5678'.
Example 1: This VBScript example stores ABCD into 'StringVar1'.
View.Substring StringVar1.Name, BarCodeStr.Value, 1, 4
Example 2: This VBScript example stores 5678 into 'StringVar1'.
View.Substring StringVar1.Name, BarCodeStr.Value, 6, 4

Example 3: In this VBScript example, InputString has the name of a model


(such as "WidgetPart M254". The example finds the part number following the
"M", up to 5 digits.
Dim StartChar
StartChar = View.StringPos ("M", InputString.Value)
View.SubString strResult.Name, InputString.Value, StartChar,
StartChar +5
PartNumber = View.StringtoNum (strResult.Value)
See Also
StringPos, StringToNum, StringFromNum, CopyDateToString,
CopyTimeToString, StringCompare, StringConCat, StringCopy
View Scripting Functions

System script functions

System functions provide access to system-level features such as controlling


log events, loading and saving recipes, and executing menu commands.
The following System Functions are available:
Function Description
AssignIndirect Points an indirect variable to another variable.
AssignIndiFromStr Points an indirect variable to another variable who's
name is stored in a string variable.
DeviceChangeDriver Toggles the driver a device is using between the primary
and the redundant driver.
GetDayOfWeek Returns an integer representing the current day of the
week.
GetDayOfYear Returns an integer representing the current day of the
year.
LogEvent Logs an event alarm with a specified description.
LogGroupEnable Turns logging on or off for all points in a logging group.
LogGroupPeriod Changes the frequency at which logging occurs for a
periodic logging group.
ValidateRecipe Checks a file to see whether it is a valid recipe file.
LoadRecipe Loads and activates a specified recipe file.
SaveRecipe Creates a recipe file using variables specified in a
template file.
RestartWindows Use RestartWindows to restart Windows PC.
RunCommand Executes a specified View Runtime or add-on module
menu function.
SetLanguage Sets the current "default language" (based on the
Languages grid) to use when language translation is
enabled.
SystemExit Exits the Runtime system.
View Scripting Functions System

AssignIndiFromStr
Points an indirect variable to another variable whose name is stored in a
STRING variable.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.AssignIndiFromStr strVarIndirectName, strVarRealName [,
numOffsetCount]

ViewScript syntax
AssignIndiFromStr varIndirect, strvarReal [, numOffsetCount]

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strVarIndirectName varIndirect A Machine Edition variable with an
Indirect data source whose variable
pointer you want to change.
strVarRealName strvarReal The name of a Machine Edition STRING
variable whose value is the name of the
analog (integer or real), BOOL, or
STRING variable that you want to assign
to the indirect variable.
numOffsetCount numOffsetCount (Optional) The offset in the variable list
from the variable stored in strvarReal.
Note: AssignIndirect will work with network variables, but only with variables that are directly
referenced in scripts and animations. In these cases, an offset (numOffsetCount) cannot be used.

Return Value
None

Comments
You cannot point an indirect variable at another indirect variable.
When using this function in an Active Scripting language (such as VBScript),
names of all items and variables in parameters must be written as string
expressions. Variable references must also use the full Machine Edition
syntax. You can acquire the full Machine Edition syntax of a variable with the
.Name property. Also, strVarIndirectName and strVarRealName cannot refer
to variables that are locally defined in VBScript with a DIM statement.

ViewScript Examples
Example 1: This ViewScript example assigns the variable whose name is
stored in the STRING variable 'Temp3' to the indirect variable
'genericSetpoint'. The first line stores the name "PID1Setpoint" in Temp3;
after the second line, the indirect variable 'genericSetpoint' will point to the
value of the variable named 'PID1Setpoint'.
StringCopy Temp3, "PID1Setpoint"
AssignIndiFromStr genericSetpoint, Temp3

Example 2: This ViewScript example does the following.

● First, it gets the full name of the "Bottom" element of the structure
variable named 'MySource', storing it in the variable named 'MySTRING'.
● Second, it assigns this to the "Bottom" element of a similar structure
variable named 'MyIndirect'. This "Bottom" element of MyIndirect is
configured as an Indirect variable.

After the second line, the variable element MyIndirect.Bottom will point to the
variable element MySource.Bottom.
StringCopy MySTRING, "MySource.Bottom"
AssignIndiFromStr MyIndirect.Bottom, MySTRING

Example 3: This ViewScript example assigns the variable whose name is


stored in the STRING variable 'TextVariable' to the indirect variable
'DisplayAlarm', with an offset of 'TextVariableOffset'. Each time the script
runs, 'TextVariableOffset' is incremented by 1. When it reaches 4, it is reset
to 0 and incremented again.
Note: The properties of the variable 'Display Alarm' must be configured properly for the offset
parameter to work. Set DataSource to Indirect. Set Variable, under DataSourceDetails to the
TextVariableOffset.
AssignIndiFromStr DisplayAlarm, TextVariable, TextVariableOffset
If TextVariableOffset = 4
TextVariableOffset := 0
ELSE
TextVariableOffset := TestVariableOffset + 1
ENDIF

Active Scripting Examples


Example 1: This VBScript example assigns the variable whose name is stored
in the STRING variable 'Temp3' to the indirect variable 'genericSetpoint'. The
first line stores the name "PID1Setpoint" in Temp3; after the second line, the
indirect variable 'genericSetpoint' will point to the value of the variable
named 'PID1Setpoint'.
View.StringCopy Temp3.Name, "PID1Setpoint"
View.AssignIndiFromStr genericSetpoint.Name, Temp3.Value
Example 2: This VBScript example does the following:

● First, it gets the full name of the "Bottom" element of the structure
variable named 'MySource', storing it in the variable named 'MySTRING'.
● Second, it assigns this to the "Bottom" element of a similar structure
variable named 'MyIndirect'. This "Bottom" element of MyIndirect is
configured as an Indirect variable.

After the second line, the variable element MyIndirect.Bottom will point to the
variable element MySource.Bottom.
View.StringCopy MySTRING.Name, MySource.Element("Bottom").Name
View.AssignIndiFromStr MyIndirect.Element("Bottom").Name,
MySTRING.Value

Example 3: This VBScript example assigns the variable whose name is stored
in the STRING variable 'TextVariable' to the indirect variable 'DisplayAlarm',
with an offset of 'TextVariableOffset'. Each time the script runs,
'TextVariableOffset' is incremented by 1. When it reaches 4, it is reset to 0
and incremented again.
Note: The properties of the variable 'Display Alarm' must be configured properly for the offset
parameter to work. Set DataSource to Indirect. Set Variable, under DataSourceDetails to the
TextVariableOffset.
View.AssignIndiFromStr displayalarm.Name, TextVariable.Name,
TextVariableOffset.Value
If TextVariableOffset.Value = 4 Then
TextVariableOffset.Value = 0
Else
TextVariableOffset.Value = TestVariableOffset.Value + 1
End If

See Also
AssignIndirect, StringCopy
View Scripting Functions System

AssignIndirect
Points an indirect variable to another variable. This command is useful when
creating and activating general-purpose panels in your project (such as a PID
faceplate).
By using an offset, you can assign an indirect to a consecutive list of
variables in the database with one script statement.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.AssignIndirect strVarIndirectName, strVarDirectName [,
numOffsetCount]

ViewScript syntax
AssignIndirect varIndirect, varDirect [, numOffsetCount]

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strVarIndirectName varIndirect The name of a Machine Edition variable
with an Indirect data source whose
variable pointer you want to change.
strVarDirectName varDirect The name of the variable to assign to the
variable specified by varIndirect or
strVarIndirectName. This can be an
analog, BOOL, or STRING variable. It
cannot have an Indirect data source.
numOffsetCount numOffsetCount (Optional) The offset in the variable list
from the variable list from varDirect.

Return Value
None

Comments
You cannot point an indirect variable at another indirect variable. You also
cannot specify indirect values using BOOL, BYTE, or WORD access
expressions, such as "AssignIndirect myIndirectBOOL myDINT.X[0]".
AssignIndirect will work with network variables, but only with variables that
are directly referenced in scripts and animations. An offset (numOffsetCount)
cannot be used.
All array elements should have "Marked as Used" set to true.
If AssignIndirect is used with the numOffsetCount parameter, variables that
aren't used in the project and have their 'Mark As Used' property set to False
are not counted in the offset.
When using this function in an Active Scripting language (such as VBScript),
names of all items and variables in parameters must be written as string
expressions. Also, strVarIndirectName and strVarDirectName cannot refer to
a variable that is locally defined in VBScript with a DIM statement.
Indirect variables are often used to animate a single object with the values of
several different (but similar) processes or real world devices at different
points in time. In this way, a single PID object can be animated with the
values from any one of many PIDs.

ViewScript Examples
Example 1: In this ViewScript example, an object is animated with a script
that uses three indirect variables: genericSetpoint, genericActual, and
genericOutput. When the script is executed, it changes the value source of
what the object is displaying, from its current PID values to the values of PID
#1.
AssignIndirect genericSetpoint, PID1Setpoint
AssignIndirect genericActual, PID1Actual
AssignIndirect genericOutput, PID1Output
Example 2: In the second ViewScript example, the variable assigned to an
indirect variable is also treated as a variable when using the numOffsetCount
parameter. The variable in the varDirect parameter is replaced by the
variable at the specified number of positions (numOffsetCount) down the
variable list (alphabetically sorted) from varDirect.
If the variable 'Tank' is an indirect variable and the variables following it in
the variable database list are 'Tank1', 'Tank2', 'Tank3', and 'Tank4', you can
use the AssignIndirect command with an analog variable or variable that
contains the tank number you want the indirect variable 'Tank' to be assigned
to.
If the variable containing the tank number is 'TankNumber', the following
command assigns 'Tank' to the appropriate variable in the list.
AssignIndirect Tank, Tank1, (TankNumber - 1)
'where TankNumber = 1, 2, 3, or 4
Since the indirect variable 'Tank' is immediately before the first tank in the
variable list, you can also write the above command as:
AssignIndirect Tank, Tank, TankNumber

Active Scripting Examples


Example 1: In this VBScript example, an object is animated with a script that
uses three indirect variables: genericSetpoint, genericActual, and
genericOutput. When the script is executed, it changes the value source of
what the object is displaying, from its current PID values to the values of PID
#1.
View.AssignIndirect genericSetpoint.Name, PID1Setpoint.Name
View.AssignIndirect genericActual.Name, PID1Actual.Name
View.AssignIndirect genericOutput.Name, PID1Output.Name
Example 2: In this VBScript example, the variable assigned to an indirect
variable is also treated as a variable when using the numOffsetCount
parameter. The variable in the varDirect parameter is replaced by the
variable at the specified number of positions (numOffsetCount) down the
variable list (alphabetically sorted) from varDirect.
If the variable 'Tank' is an indirect variable and the variables following it in
the variable database list are 'Tank1', 'Tank2', 'Tank3', and 'Tank4', you can
use the AssignIndirect command with an analog variable or variable that
contains the tank number you want the indirect variable 'Tank' to be assigned
to.
If the variable containing the tank number is 'TankNumber', the following
command assigns 'Tank' to the appropriate variable in the list.
View.AssignIndirect Tank.Name, Tank1.Name, (TankNumber.Value - 1)
'where TankNumber = 1, 2, 3, or 4
Since the indirect variable 'Tank' is immediately before the first tank in the
variable list, you can also write the above command as:
View.AssignIndirect Tank.Name, Tank.Name, TankNumber.Value

See Also
AssignIndiFromStr
View Scripting Functions System

DeviceChangeDriver
Toggles the driver that a device is using between the primary and the
redundant driver. You can set a redundant driver by clicking on the PLC
Access Drivers node in the Navigator, expanding a driver, selecting a
device, and editing device properties in the Inspector.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.DeviceChangeDriver strDeviceName

ViewScript syntax
DeviceChangeDriver strDeviceName

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strDeviceName strDeviceName String expression containing the name of
the device whose driver you want to
change. The parameter must be either a
literal string, or a STRING variable.

Return Value
None

Comments
strDeviceName should be the device name of the primary driver, not the
secondary (redundant) driver. This command works only when redundant
communications are enabled for the specific device.

ViewScript Example
The following ViewScript example toggles the driver and address that the
device 'photoeye' is using.
DeviceChangeDriver "photoeye"
Active Scripting Example
This sample is the same as above, written in VBScript.
View.DeviceChangeDriver "photoeye"
View Scripting Functions System

GetDayOfWeek
Retrieves the current day of the week.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.GetDayOfWeek

ViewScript syntax
GetDayOfWeek

Parameters
None.

Return Value
An integer corresponding to the current day of the week:
Day of the week Returned Value
Sunday 1
Monday 2
Tuesday 3
Wednesday 4
Thursday 5
Friday 6
Saturday 7

ViewScript Example
The following ViewScript example retrieves a return value representing the
current day of the week, and store the value in the variable AnalogVar.
AnalogVar := GetDayOfWeek

Active Scripting Example


This sample is the same as above, written in VBScript.
AnalogVar.Value = View.GetDayOfWeek
See Also
GetDayOfYear
View Scripting Functions System

GetDayOfYear
Retrieves the current day of the year as an integer.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.GetDayOfYear

ViewScript syntax
GetDayOfYear

Parameters
None.

Return Value
An integer corresponding to the current day of the year. For example, on
January 1st the return value would be 1, on January 2nd the return value
would be 2, and so on.
Note: During a leap year, return values range from 1 to 366. You will need to take leap years into
consideration if you are associating specific return values with dates after February 28th during a
leap year.

ViewScript Example
The following ViewScript example retrieves a return value representing the
current day of the year, and store the value in the variable AnalogVar.
AnalogVar := GetDayOfYear

Active Scripting Example


This sample is the same as above, written in VBScript.
AnalogVar.Value = View.GetDayOfYear

See Also
GetDayOfWeek
View Scripting Functions System

LoadRecipe
Loads and activates the specified recipe file. View recipes can be text files
with one or more statements that modify the values of one or more variables
in the database.
LoadRecipe looks for the text file passed as a parameter and if found, reads it
and interprets it as a series of statements that assign a value or the result of
an expression to a database variable.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.LoadRecipe strFileName [, numExtensionNumber]

ViewScript syntax
LoadRecipe strFileName [, numExtensionNumber]

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strFileName strFileName String expression containing the
path and file name of the recipe
text file. Use either a literal
string or a STRING variable.
If you do not include the
numExtensionNumber
parameter, then strFileName
should include the file name
extension.
numExtensionNumber numExtensionNumber (Optional) An Integer expression
used as a file name extension.
The integer can be a number
from 0 through 999. When this
parameter is used, the actual
recipe name is constructed by
combining the first parameter
with a numeric extension, as in
"MyFile.036".

Return Value
None

Comments
The recipe text file must use the ViewScript syntax to assign variables.
Statements in a recipe file can assign values to variables using literal
numbers, variables, and mathematical expressions. Recipe files cannot use
script functions or variable fields.
If a recipe file includes references to other variables in the Variable List, set
the Mark As Used property on those variables to True. By default, Machine
Edition does not include a variable in a downloaded project if no references to
that variable can be found. Since Machine Edition ignores recipe files when
checking variable references, you must use the Mark As Used property to
force those variables to be included.
Tip: If you include the recipe file as a downloadable Supplemental File, you do not need to include
a path name in strFileName. Supplemental Files get downloaded to "fxView\Runtime\PROJECT"
under the Machine Edition installation directory on the runtime computer. By default, Machine
Edition is installed to "C:\Program Files\GE IP\Proficy Machine Edition".

Recipe file format notes


The following rules apply to statements in recipe files.

● When using variable names in recipes, you must use the whole name of
the variable as it appears in the Variable List.
● If a variable array has more than 10 elements, you must include leading
"0" characters in the array index reference. For example, MyStructArray
is an array with 15 elements. Each structure has a Var element. You
would use MyStructArray[01].var to refer to the var element of
structure 1 in the array.
● When assigning string variables, do not include quotation marks.
● Assignment statements cannot use script functions or variable fields.
● Recipe files can contain comments. If a single quotation mark is
encountered ('), that character and all subsequent characters on the line
are ignored.
Therefore, When using single quotation marks in a string assignment,
you must "escape" the quotation mark with a backslash character (\).
For example, to assign the string "abc'def" to a variable, you would use
"abc\'def" instead.

The following ViewScript statements illustrate assignment statements that


can be used in a recipe text file:
MyLREAL1 := (COS MyLREAL2) * 10
MyDINT1 := 333
MyDINT2 := variable01 * variable02
MyDINT4 := ((variable01 + variable02 + variable03) * variable04) -
variable05
MyBOOL := 1
MySTRING := abc\'def
Note: The final example uses a backslash to escape the quotation mark, assigning the string
abc'def to the MySTRING variable.

ViewScript Examples
Example 1: The following ViewScript examples include the full file name
extension.:
LoadRecipe "MIXING.TXT"
LoadRecipe "D:\RECIPES\PLCMAIN.TXT"
Example 2: If the ViewScript application contains the variable 'RecipeId' with
a value of 23, calling:
LoadRecipe "CAKE", RecipeId
loads the file 'CAKE.023'.

Active Scripting Examples


Example 1: The following VBScripts include the full file name extension.:
View.LoadRecipe "MIXING.TXT"
View.LoadRecipe "D:\RECIPES\PLCMAIN.TXT"
Example 2: If the VBScript application contains the variable 'RecipeId' with a
value of 23, calling:
View.LoadRecipe "CAKE", RecipeId.Value
loads the file 'CAKE.023'.
Note:
Note: Within a recipe file, statements must be written in ViewScript—even if the script that reads it
is written in VBScript. See Recipe File format notes above.

See Also
ValidateRecipe, SaveRecipe
View Scripting Functions System

LogEvent
Causes an event alarm with a description equal to the strEventString.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.LogEvent strEventString

ViewScript syntax
LogEvent strEventString

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strEventString strEventString String expression with the description of
your event. This can have a maximum of
80 characters. Use either a literal string
or a STRING variable.

Return Value
None

Comments
This event appears and acts exactly like any of the system generated event
alarms. Use this command in scripts to supplement the generated system
alarms.

ViewScript Examples
Example 1: This ViewScript example is used in a script that is triggered by
the generator shutting down.
LogEvent "Generator has shutdown"
Example 2: This second ViewScript example causes an event alarm and
attaches the comment stored in the "OperatorComment" variable.
LogEvent OperatorComment
Active Scripting Examples
Example 1: This VBScript example is used in a script that is triggered by the
generator shutting down.
View.LogEvent "Generator has shutdown"
Example 2: This second VBScript example causes an event alarm and
attaches the comment stored in the "OperatorComment" variable.
View.LogEvent OperatorComment.Value
View Scripting Functions System

LogGroupEnable
Toggles logging on or off for all variables in a logging group.
Note: Variables must have logging enabled in the Variable Database Editor in order to toggle its
logging state in Runtime.

Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.LogGroupEnable strLoggrpName, numLogState

ViewScript syntax
LogGroupEnable loggrpName, numLogState

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strLoggrpName loggrpName The name of the logging group to
modify.
numLogState numLogState Integer indicating whether logging should
be turned on or off. Set to 0 to disable
logging for the specified group. Set to 1
to enable logging.

Return Value
None

Comments
When using this function in an Active Scripting language (such as VBScript),
names of all items and variables in parameters must be written as string
expressions.

ViewScript Example
The following ViewScript example turns logging on for all points in the
'Pipeline' logging group.
LogGroupEnable Pipeline, 1
Active Scripting Example
This sample is the same as above, written in VBScript.
View.LogGroupEnable "Pipeline", 1
View Scripting Functions System

LogGroupPeriod
Changes the frequency or time interval at which logging occurs for a logging
group configured as periodic.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.LogGroupPeriod strLogGrpName, numPeriodLength

ViewScript syntax
LogGroupPeriod loggrpName, numPeriodLength

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strLogGrpName loggrpName The name of a logging group whose
Logging Strategy property is set to
Periodic.
numPeriodLength numPeriodLength An integer expression indicating the new
length of the time interval between which
logging occurs, in seconds.

Return Value
None

Comments
This function effectively changes the logging group's Frequency property.
Note that with LogGroupPeriod, you can specify any number of seconds,
rather than selecting a specific frequency from a list.
LogGroupPeriod will not work if the indicated logging group is not periodic.
When using this function in an Active Scripting language (such as VBScript),
names of all items and variables in parameters must be written as string
expressions.
Note: The Logging Groups folder's Log Data Every property forces additional logging to occur at
specific intervals for all logging groups. This occurs in addition to logging events that occur due the
logging group's Frequency property; it cannot be turned off with the LogGroupPeriod function.

ViewScript Example
The following ViewScript example changes the frequency of the logging group
MyLogGroup to 30 minutes.
LogGroupPeriod MyLogGroup, 1800

Active Scripting Example


This sample is the same as above, written in VBScript.
View.LogGroupPeriod "MyLogGroup", 1800
View Scripting Functions System

RestartWindows
Restarts Windows PC. Useful when creating applications that will not display a
standard windows pull-down menu.
Note: Some applications may halt the Windows shutdown process. For example, if the Machine
Edition editor is open and you execute a script that contains the RestartWindows function you will
be asked whether or not you want to close Machine Edition. The shutdown process will then stop.
This is a limitation of Windows PC.

Supported by: Windows PC targets

Active Scripting syntax


View.RestartWindows numDontAskConfirm

ViewScript syntax
RestartWindows numDontAskConfirm

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
numDontAskConfirm numDontAskConfirm The Restart Windows prompt is
suppressed when this number is
any non-zero integer. The prompt
will appear if numDontAskConfirm
is zero.

Return Value
None

ViewScript Example
RestartWindows myRestartWin

Active Scripting Example


This sample is the same as above, written in VBScript.
View.RestartWindows myRestartWin.Value
See Also
Logon, Logoff, SystemExit
View Scripting Functions System

RunCommand
Executes a Runtime command.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.RunCommand strModuleName, strFunctionString

ViewScript syntax
RunCommand ModuleName, strFunctionString

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strModuleName ModuleName The module whose menu commands you
want to activate. Current options include
REPORTS and SYSTEM. SYSTEM refers to
the View Runtime, while other options
are defined by the add-on module you
purchase.
strFunctionString strFunctionString This is the command string specifying
which menu option to execute. The table
in Comments below defines the
command strings for the SYSTEM
module.

Return Value
None

Comments
The following table illustrates the possible values of strFunctionString and
their effects.
strFunctionString Action
VarDatabase Open the Variable Database Inspector.
DriverDiagnostics Open Driver Diagnostics Log Viewer.
ToggleLogic Start/stop script execution, reversing its previous state.
AboutBox Open the About Box dialog box.
Debug Open the Logic Debugger.

ViewScript Example
The following ViewScript example executes the command "VarDatabase" from
the Database menu in View Runtime. This opens the Variable Database
Inspector dialog box.
RunCommand System, "VarDatabase"

Active Scripting Example


This sample is the same as above, written in VBScript.
View.RunCommand "System", "VarDatabase"
View Scripting Functions System

SaveRecipe
Creates a recipe file using a template file containing the variable names
needed in the recipe.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.SaveRecipe strTemplate, strFileName [, numExtensionNumber]

ViewScript syntax
SaveRecipe strTemplate, strFileName [, numExtensionNumber]

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strTemplate strTemplate String expression with the path
and file name of the template
text file. The template text file is
a text file with one entry per
line, the entry being the variable
name to be saved. Use either a
literal string or a STRING
variable.
strFileName strFileName String expression with the path
and file name of the recipe text
file you want to save the recipe
in. Use either a literal string or a
STRING variable. If you do not
include the
numExtensionNumber
parameter, strFileName should
include the file name extension.
numExtensionNumber numExtensionNumber (Optional) Integer expression
used as a file name extension.
The integer can be a number
from 0 through 999. When this
parameter is used, the actual
recipe name is constructed by
combining the first parameter
with a numeric extension, as in
"MyFile.036".

Return Value
This function returns 1 if successful, 0 otherwise.

Comments
To ensure files are created in the correct directory, specify the full file path of
the recipe file.
Tip: If you include the template file as a downloadable Supplemental File, you do not need to
include a path name in strTemplate. Supplemental Files get downloaded to
"fxView\Runtime\PROJECT" under the Machine Edition installation directory on the runtime
computer. By default, Machine Edition is installed to "C:\Program Files\GE IP\Proficy Machine
Edition".

ViewScript Example
In the following ViewScript example, below the template file sample.txt
contains the following four lines:
variable1
variable2
variable3
AnotherVariable
The values for the above variables are 3, 4.5, 7, and 'Hello' respectively. The
ViewScript command:
SaveRecipe "sample.txt", "c:\data\View\recipe1.rcp"
will cause the following 4 lines to be stored in the file recipe1.rcp:
' recipe length = 4
variable1 := 3
variable2 := 4.5
variable3 := 7
AnotherVariable := Hello
You can load the resulting recipe using the LoadRecipe command.
Note: When using variable names in recipes, you must use the whole name of the variable as it
appears in the Variable List. Also, if a variable array has more than 10 elements, you must include
leading 0's in the array index reference. For example, MyStructArray is an array with 15 elements.
Each structure has a Var element. You would use MyStructArray[01].var to refer to the
var element of structure 1 in the array.

Active Scripting Example


This sample is the same as above, written in VBScript.
View.SaveRecipe "sample.txt", "c:\data\View\recipe1.rcp"

See Also
ValidateRecipe, LoadRecipe
View Scripting Functions System

SetLanguage
Sets the current language in the Languages grid, to be used if language
translation is enabled for the target.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.SetLanguage strLanguageName

ViewScript syntax
SetLanguage strLanguageName

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strLanguageName strLanguageName String expression with the name of the
language to set as the current language
for the target. This should correspond
with the header of one of the columns in
the Languages grid. If you want to set
the current language to the original
source text, use an empty string ("").

Return Value
This function returns 1 if the new language was set successfully, 0 otherwise.
Note: If Language Translation is disabled for the target, SetLanguage will always fail.

Comments
If the Language Translation property of a target's Languages item is set to
True, Proficy Machine Edition includes entries in the Languages grid when
downloading the project to the target. This grid specifies a series of
translations for text on the target's graphical panels. When displaying the
HMI, the runtime translates all text on graphical panels based on the "current
language".
You specify the default current language when configuring the grid. The
SetLanguage function lets you also change the current language at run
time—perhaps in response to a button click by the user.
When using Alarm Display objects or the Alarm Manager console, each alarm
message that is displayed is translated upon a call to SetLanguage.
Depending on the number of alarm messages, performance of the HMI may
temporarily degrade during this period.

ViewScript Example
The following ViewScript example sets the current language to "French".
MySetLanguageStatus := SetLanguage "French"

Active Scripting Example


This sample is the same as above, written in VBScript.
MySetLanguageStatus.Value = View.SetLanguage ("French")
View Scripting Functions System

SystemExit
Exits Runtime. Useful when creating applications that will not display a
standard windows pull-down menu.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.SystemExit numDontAskConfirm

ViewScript syntax
SystemExit numDontAskConfirm

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
numDontAskConfirm numDontAskConfirm Integer indicating whether the user
should be prompted for
confirmation. If a positive integer
value, the exit prompt is
suppressed. If any other value, the
exit prompt is not suppressed.

Return Value
None

ViewScript Example
SystemExit myConfirm

Active Scripting Example


This sample is the same as above, written in VBScript.
View.SystemExit myConfirm.Value

See Also
Logon, Logoff, RestartWindows
View Scripting Functions System

ValidateRecipe
Checks whether a specified recipe file is valid. View recipes can be text files
with one or more statements that modify the values of one or more variables
in the database. Typically, a script calls ValidateRecipe before calling
LoadRecipe.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.ValidateRecipe strFileName, [, numVarLineInErrorName] [,
numExtensionNumber]

ViewScript syntax
ValidateRecipe strFileName, [numVarLineInError,]
[numExtensionNumber]

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strFileName strFileName String expression with the
path and file name of the
recipe text file. Use either a
literal string or a STRING
variable. If the
numExtensionNumber
parameter is not used,
strFileName should include
the file name extension.
strNumvarLineInErrorName numvarLineInError (Optional) A Machine
Edition DINT or LREAL
variable that will contain
the line number that
applies to the returned
error, if applicable.
Comment lines are included
in this number count.
Applicable returned error
codes are -4 (the recipe file
refers to a nonexistent or
invalid variable), -5 (the
value assigned to a recipe
variable is outside the
specified range), and -6 (a
line in the recipe contains
an invalid expression).
numExtensionNumber numExtensionNumber (Optional) An Integer
expression used as a file
name extension. The
integer can be a number
from 0 through 999. When
this parameter is used, the
actual recipe name is
constructed by combining
the first parameter with a
numeric extension, as in
"MyFile.036".

Return Value
This function returns one of the following values.
Value Meaning
0 Valid Recipe: The recipe file passed all validity checks
-1 Not found: The specified recipe file could not be found or could not be
accessed.
-2 Contains no statements: No statements could be found in the recipe
file.
-3 Incorrect length: The number of variables in the recipe file does not
match the recipe length. The recipe length is specified in a comment
string in the first line of the recipe file. For example:
‘ recipe length = 3
var01 := 100
var02 := 5
var03 := 21.5
Tip: The script function SaveRecipe now creates recipe files with this information.

-4 Invalid variable: A variable referenced in the recipe file does not


exist. The number of the line with the invalid reference is stored in the
variable specified by the numVarLineInError parameter, if used.
-5 Out of range: A value assigned to a variable in the recipe file is
beyond the variable's specified range limits. The range limits for a
variable are specified in its Range Limits Low and Range Limits High
properties.
-6 Invalid expression: The recipe file contains an invalid expression.
For example, the assignment operator (":=") may be missing or the
left side of the expression may not evaluate to a numerical value.

Comments
This function returns as soon as it finds an error in the recipe file. There may
be additional errors in the file following that first error. For example, there
may be several invalid variables in the recipe file, but only the first one
encountered is indicated in numVarLineInError or
strNumVarLineInErrorName.
When using this function in an Active Scripting language (such as VBScript),
names of all items and variables in parameters must be written as string
expressions. Also, strNumvarLineInErrorName cannot refer to a variable that
is locally defined in VBScript with a DIM statement.
See LoadRecipe for more information on recipe files.

ViewScript Example
The following ViewScript example uses ValidateRecipe to check the recipe file
"recipe01.txt". If it is valid, the recipe is loaded. If not, an error message is
displayed and the recipe file is not loaded.
DECLARE _validateResult
_validateResult := ValidateRecipe "recipe01.txt"
IF _validateResult = 0
LoadRecipe "recipe01.txt"
ELSE
Message "Bad recipe file!"
ENDIF

Active Scripting Example


This sample is the same as above, written in VBScript.
Dim validateResult
validateResult = View.ValidateRecipe ("recipe01.txt")

If validateResult = 0 Then
View.LoadRecipe "recipe01.txt"
Else
View.Message "Bad recipe file!"
End If

See Also
LoadRecipe, SaveRecipe
View Scripting Functions

Trend Management Script Functions

Use trend management functions to configure Trend objects in your View


HMI. Trend objects are added to an HMI with the Trend tool on the Graphical
Editor toolbar.
The following Trend Management Functions are described in this section:

Function Description
TrendClear Clears the Trend object.
TrendContinueDisplay Resumes previously paused trending on a Trend object.
TrendEdit Opens the Trend Pen Manager dialog box, which allows
the end user to edit trend pens for a trend object.
TrendPauseDisplay Pauses trending on a Trend object.
TrendPrint Prints the current display on a Trend object.
TrendSetRange Sets the range for a Trend object .
TrendSetRate Sets the scan rate (in seconds) for recording values in
a Trend display.
TrendTrigger Allows you to manually trigger trending. Works with
the Manual Trigger feature in the Inspector.
View Scripting Functions Trend

TrendClear
Clears all data from the specified Trend display object and restarts
trending.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.TrendClear strTrendobjName

ViewScript syntax
TrendClear trnobjName

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strTrendobjName trnobjName The name of the Trend object.

Comments
With TrendClear, the specified Trend display object doesn't have to appear on
the current panel.
When using this function in an Active Scripting language (such as VBScript),
names of all items and variables in parameters must be written as string
expressions.
For more information on trend display objects, see Trend Objects.

Return Value
None

ViewScript Example
The following ViewScript example clears all data from the Trend display
object 'myTrend', and restarts trending.
TrendClear myTrend

Active Scripting Example


This sample is the same as above, written in VBScript.
View.TrendClear "myTrend"

See Also
TrendEdit, TrendPrint, TrendSetRange, TrendSetRate
View Scripting Functions Trend

TrendContinueDisplay
Resumes the display of pen values after trending has been paused using
TrendPauseDisplay.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.TrendContinueDisplay strTrendobjName

ViewScript syntax
TrendContinueDisplay trnobjName

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strTrendobjName trnobjName The name of the trend object you want
to resume display in.

Return Value
None

Comments
This function is used with the TrendPauseDisplay function. It is useful when
you want to display a block of values all at once. It is also useful when you
want the trend object to update at a slower rate than its scan rate without
losing trend data.
When using this function in an Active Scripting language (such as VBScript),
names of all items and variables in parameters must be written as string
expressions.
For more information on trend display objects, see Trend Objects.

ViewScript Examples
Example 1: This ViewScript example pauses the display of 'Trend1', trends
the values of pens 1 and 2, then uses TrendContinueDisplay to continue
trending on the Trend display and updates it with the latest trend values. Pen
1 displays the values of 'Variable1' and Pen 2 displays the values of
'Variable2'.
TrendPauseDisplay Trend1
Variable1 := 10
Variable2 := 25
TrendContinueDisplay Trend1
Example 2: This second ViewScript example updates the display of 'Trend1'
every minute, while the Trend object continues to collect data at the scan
rate configured in the Update Interval property in the Inspector. If the
Update Interval is set to one second, the 60 data points collected during the
pause are displayed as a pen trail when the trend is updated.
With the "on condition" activation type set in the Inspector, the following
script runs when the one minute pause has ended. The Trend object is
updated with 60 seconds of data, then the display pauses for one minute.
TrendContinueDisplay Trend1
Sleep 1
TrendPauseDisplay Trend1

Active Scripting Example


This VBScript example pauses the display of 'Trend1', trends the values of
pens 1 and 2, and then uses TrendContinueDisplay to continue trending on
the Trend display and update it with the latest trend values. Pen 1 displays
the values of 'Variable1' and Pen 2 displays the values of 'Variable2'.
View.TrendPauseDisplay "Trend1"
Variable1.Value = 10
Variable2.Value = 25
View.TrendContinueDisplay "Trend1"

See Also
TrendPauseDisplay , TrendTrigger
View Scripting Functions Trend

TrendEdit
Displays the Edit Trend Pens dialog box for a specified Trend Display
object.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.TrendEdit strTrendwinName

ViewScript syntax
TrendEdit trnwinName

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strTrendwinName trnwinName The name of the trend object.

Return Value
None

Comments
Use the system variable #AccessLevel to ensure that only authorized users
can edit the trend object.
The specified trend object must appear on a currently-displayed panel.
When using this function in an Active Scripting language (such as VBScript),
names of all items and variables in parameters must be written as string
expressions.

● For more information on the Trend Pen Manager, see Trend Pen
Manager dialog box.
● For more information on trend display objects, see Trend Objects.

Warning: When viewing QuickPanel View/Control HMI graphical panels remotely over the web
(see Remote Viewing of View Runtime), any dialog boxes that are opened because of actions
performed remotely on the HMI will not be closed on the QuickPanel View/Control display. This
will eventually cause the HMI application to fail. If you want to use a script function that opens a
dialog box on a QuickPanel View/Control target, it is highly recommended that you do not allow the
users to operate the HMI remotely.

ViewScript Example
The following ViewScript example opens the Trend Pen dialog box, restricting
access to users with a security level greater than 100.
If #AccessLevel > 100
TrendEdit TempTrends
ENDIF

Active Scripting Example


This sample is the same as above, written in VBScript.
If AccessLevel.Value > 100 Then
View.TrendEdit "TempTrends"
End If

See Also
TrendClear, TrendPrint, TrendSetRange, TrendSetRate
View Scripting Functions Trend

TrendPauseDisplay
Pauses the display of the specified Trend object.
This script function is useful to display blocks of values at once. It is also
useful when you want the Trend object to update values at a slower rate than
its scan rate without losing trend data.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.TrendPauseDisplay strTrendobjName

ViewScript syntax
TrendPauseDisplay trnobjName

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strTrendobjName trnobjName The name of the Trend object whose
trending you want to pause.

Return Value
None

Comments
This function is used with the TrendContinueDisplay function.
When using this function in an Active Scripting language (such as VBScript),
names of all items and variables in parameters must be written as string
expressions.
For more information on trend display objects, see Trend Objects.

ViewScript Examples
Example 1: This ViewScript example pauses the display of 'Trend1' using
TrendPauseDisplay, trending the values of pens 1 and 2. It then resumes the
Trend display using TrendContinueDisplay and updates it with the latest trend
values. Pen 1 displays the values of 'Variable1' and Pen 2 displays the values
of 'Variable2'.
TrendPauseDisplay Trend1
Variable1 := 10
Variable2 := 25
TrendTrigger Trend1
Variable1 := 20
Variable2 := 30
TrendTrigger Trend1
Variable1 := 30
Variable2 := 35
TrendTrigger Trend1
TrendContinueDisplay Trend1
Note: To use TrendTrigger the Manual Trigger property in the Inspector must be enabled.

Example 2: This ViewScript example updates the Trend display of 'Trend1'


every minute while the Trend object continues to collect data at the scan rate
configured in Update Interval property in the Inspector. If the Update
Interval is set to one second, the 60 data points collected during the pause
are displayed as a pen trail when the trend is updated.
With the "on condition" activation type set in the Inspector, the following
script runs when the one minute pause has ended. The Trend object is
updated with 60 seconds of data, then the display pauses for another minute.
TrendContinueDisplay Trend1
Sleep 1
TrendPauseDisplay Trend1

Active Scripting Example


This VBScript example pauses the display of 'Trend1' using
TrendPauseDisplay, trending the values of pens 1 and 2. It then resumes
trending for the Trend display using TrendContinueDisplay and update it with
the latest trend values. Pen 1 displays the values of 'Variable1' and Pen 2
displays the values of 'Variable2'.
View.TrendPauseDisplay "Trend1"
Variable1.Value = 10
Variable2.Value = 25
View.TrendTrigger "Trend1"
Variable1.Value = 20
Variable2.Value = 30
View.TrendTrigger "Trend1"
Variable1.Value = 30
Variable2.Value = 35
View.TrendTrigger "Trend1"
View.TrendContinueDisplay "Trend1"
Note: To use TrendTrigger, the Manual Trigger property in the Inspector must be enabled.

See Also
TrendContinueDisplay , TrendTrigger
View Scripting Functions Trend

TrendPrint
Takes a snapshot of a specified Trend object and sends it to the default
printer.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.TrendPrint strTrendobjName

ViewScript syntax
TrendPrint trnobjName

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strTrendobjName trnobjName The name of the Trend object to print.

Return Value
None

Comments
When using this function in an Active Scripting language (such as VBScript),
names of all items and variables in parameters must be written as string
expressions.
For more information on trend display objects, see Trend Objects.

ViewScript Example
The following ViewScript example takes a snapshot of the trend object
'myTrend' and sends it to the default printer.
TrendPrint myTrend

Active Scripting Example


This sample is the same as above, written in VBScript.
View.TrendPrint "myTrend"
See Also
TrendClear, TrendEdit, TrendSetRange, TrendSetRate
View Scripting Functions Trend

TrendSetRange
Sets the range for a currently-displayed Trend object.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.TrendSetRange strTrendobjName [, numNewMin, numNewMax]

ViewScript syntax
TrendSetRange trnobjName, numNewMin, numNewMax

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strTrendobjName trnobjName The name of the Trend object for which
you want to set a range.
numNewMin numNewMin (Optional) Numerical expression
indicating the minimum value to be
displayed on the Trend object.
numNewMax numNewMax (Optional) Numerical expression
indicating the maximum value to be
displayed on the Trend object.

Return Value
None

Comments
You can use integer or floating point variables for numNewMin and
numNewMax, allowing the user to change these values in Runtime.
The specified Trend object must appear on a currently-displayed panel.
Changing the range clears the trend display.
When using this function in an Active Scripting language (such as VBScript),
names of all items and variables in parameters must be written as string
expressions.
For more information on Trend Display objects, see Trend Objects.

ViewScript Examples
Example 1: This ViewScript example changes the range of 'Trend1' by
prompt.
TrendSetRange Trend1
Example 2: This ViewScript example changes the range of 'Trend1' from 10
to 100.
TrendSetRange Trend1, 10, 100
Example 3: This ViewScript example changes the range of 'Trend1' from the
value of 'MinVar' to 'MaxVar'.
TrendSetRange Trend1, MinVar, MaxVar

Active Scripting Examples


Example 1: This VBScript example changes the range of 'Trend1' by prompt.
View.TrendSetRange "Trend1"
Example 2: This VBScript example changes the range of 'Trend1' from 10 to
100.
View.TrendSetRange "Trend1", 10, 100
Example 3: This VBScript example changes the range of 'Trend1' from the
value of 'MinVar' to 'MaxVar'.
View.TrendSetRange "Trend1", MinVar.Value, MaxVar.Value

See Also
TrendSetRate, TrendTrigger
View Scripting Functions Trend

TrendSetRate
Sets the scan rate in seconds for recording values in a Trend object.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.TrendSetRate strTrendobjName [, numNewRate]

ViewScript syntax
TrendSetRate trnobjName, numNewRate

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strTrendobjName trnobjName The name of the Trend object you want
to set the scan rate for.
numNewRate numNewRate (Optional) The scan rate for the Trend
object. This can be a constant or variable
value.

Return Value
None

Comments
The specified Trend display object doesn't have to appear on the current
panel. Regardless, changing the scan rate clears the trend display.
When using this function in an Active Scripting language (such as VBScript),
names of all items and variables in parameters must be written as string
expressions.
For more information on trend display objects, see Trend Objects.

ViewScript Examples
Example 1: This ViewScript example prompts you to change the rate of
trend01.
TrendSetRate Trend01
Example 2: This ViewScript example changes the scan rate of Trend01 to 0.5
seconds.
TrendSetRate Trend01, 0.5
Example 3: This ViewScript example changes the scan rate of Trend01 to
reflect the value of RateVar.
TrendSetRate Trend01, RateVar

Active Scripting Examples


Example 1: This VBScript example prompts you to change the rate of
trend01.
View.TrendSetRate "Trend01"
Example 2: This VBScript example changes the scan rate of Trend01 to 0.5
seconds.
View.TrendSetRate "Trend01", 0.5
Example 3: This changes the scan rate of Trend01 to reflect the value of
RateVar.
View.TrendSetRate "Trend01", RateVar.Value

See Also
TrendSetRange, TrendTrigger
View Scripting Functions Trend

TrendTrigger
Trends a single point for a Trend object whose Manual Trigger property is
set to True.
This function works with a Trend object's Manual Trigger property in the
Inspector.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.TrendTrigger strTrendobjName

ViewScript syntax
TrendTrigger trnobjName

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strTrendobjName trnobjName The name of the Trend object to trend a
point from.

Return Value
None

Comments
The specified Trend object's Manual Trigger property must be True for the
TrendTrigger function to work.
Note: Each call of the TrendTrigger function trends a single point only.

The TrendTrigger script function is useful when you want a Trend display to
trend a value only while certain conditions are met. For example, you can
configure a script to run only while "Machine1" is turned on, meaning that
there is no need to trend data when the machine is off. You might then turn
trending off for a trend object linked with the machine's data, triggering
trending only while Machine1 is on.
When using this function in an Active Scripting language (such as VBScript),
names of all items and variables in parameters must be written as string
expressions.
For more information on trend display objects, see Trend Objects.

ViewScript Example
The following ViewScript example trends a single point from the trend
'Machine1'.
TrendTrigger Machine1

Active Scripting Example


This sample is the same as above, written in VBScript.
View.TrendTrigger "Machine1"

See Also
TrendPauseDisplay , TrendContinueDisplay
View Scripting Functions

Video and Sound script functions

The Video and Sound Functions allow you to add and control multimedia to
your project.
The following Video and Sound Functions are available:
Function Description
AviClose Closes an open video.
AviOpen Opens a video you want to play.
AviPause Pauses an open video.
AviPlay Plays an open video.
AviRewind Rewinds an open video that has been played.
Beep Causes the computer to beep using the internal PC speaker. A
sound card is not required.
PlaySound Plays the sound wave specified as a parameter, provided your
system is equipped with a sound card and appropriate drivers.
View Scripting Functions Video/Sound

AviClose
Stops and closes an .AVI multimedia file.
Supported by: Windows PC targets

Active Scripting syntax


View.AviClose

ViewScript syntax
AviClose

Return Value
None

Comment
This function is not currently available on QuickPanel View/Control units.

ViewScript Example
The following ViewScript example opens the "spark" video, placing the
window at coordinates (100, 100), with a size of 200 x 100 pixels. The video
is closed after it plays.
AviOpen "C:\PROGRAM FILES\GE FANUC\PROFICY MACHINE
EDITION\COMMON\IDE\CYBERS.AVI", 100, 100, 200, 100
AviPlay
SLEEP 30
AviClose

Active Scripting Example


This sample is the same as above, written in VBScript.
View.AviOpen "C:\PROGRAM FILES\GE FANUC\PROFICY MACHINE
EDITION\COMMON\IDE\CYBERS.AVI", 100, 100, 200, 100
View.AviPlay
View.AviClose

See Also
AviOpen, AviPause, AviPlay, AviRewind
View Scripting Functions Video/Sound

AviOpen
Opens a specified AVI multimedia file. You must use AviPlay to play the AVI
file.
Note: To free Windows resources, close AVI windows when you are finished using them.

Supported by: Windows PC targets

Active Scripting syntax


View.AviOpen strAviFile, numXPos, numYPos, numWidth, numHeight

ViewScript syntax
AviOpen strAviFile, numXPos, numYPos, numWidth, numHeight

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strAviFile strAviFile String expression indicating the path and
file name of the AVI file you want to
play. Use either a literal string or a string
variable.
numXPos numXPos Integer indicating the horizontal
coordinate to position the window.
numYPos numYPos Integer indicating the vertical coordinate
to position the window.
numWidth numWidth Integer indicating the width of the
display window.
numHeight numHeight Integer indicating the height of the
display window.

Return Value
None

Comments
The origin of screen coordinates are in the upper-left corner of your screen.
This function is not currently available on QuickPanel View/Control units.
ViewScript Example
The following ViewScript example opens the "spark" video, placing the
window at coordinates (100, 100), with a size of 200 x 100 pixels. The video
is closed after it plays.
AviOpen "C:\PROGRAM FILES\GE FANUC\PROFICY MACHINE
EDITION\COMMON\IDE\CYBERS.AVI", 100, 100, 200, 100
AviPlay
SLEEP 30
AviClose

Active Scripting Example


This sample is the same as above, written in VBScript.
View.AviOpen "C:\PROGRAM FILES\GE FANUC\PROFICY MACHINE
EDITION\COMMON\IDE\CYBERS.AVI", 100, 100, 200, 100
View.AviPlay
View.AviClose

See Also
AviClose, AviPause, AviPlay, AviRewind
View Scripting Functions Video/Sound

AviPause
Temporarily stops a playing AVI multimedia file.
Supported by: Windows PC targets

Active Scripting syntax


View.AviPause

ViewScript syntax
AviPause

Return Value
None

Comment
This function is not currently available on QuickPanel View/Control units.

See Also
AviClose, AviOpen, AviPlay, AviRewind
View Scripting Functions Video/Sound

AviPlay
Plays an open AVI multimedia file.
Supported by: Windows PC targets

Active Scripting syntax


View.AviPlay

ViewScript syntax
AviPlay

Return Value
None

Comments
Use AVIPlay to resume an AVI after using AVIPause.
This function is not currently available on QuickPanel View/Control units.

See Also
AviClose, AviOpen, AviPause, AviRewind
View Scripting Functions Video/Sound

AviRewind
Rewinds the AVI multimedia video that has been opened. Once a video has
been played, it must be rewound before it can be played again.
Supported by: Windows PC targets

Active Scripting syntax


View.AviRewind

ViewScript syntax
AviRewind

Return Value
None

Comment
This function is not currently available on QuickPanel View/Control units.

See Also
AviClose, AviOpen, AviPause, AviPlay
View Scripting Functions Video/Sound

Beep
Plays a beep or one of the system sounds from the internal PC speaker. A
sound card is not required.
Supported by: Windows PC targets

Active Scripting syntax


View.Beep [numBeepSound]

ViewScript syntax
Beep [numBeepSound]

Parameters
Active Scripting ViewScript Description
numBeepSound numBeepSound (Optional) Integer expressing indicating
the system beep sound to play. A table
of valid numBeepSound values can be
found in the Comments section.

Return Value
None

Comment
You can also use the PlaySound command to play wave files if you have a
sound card.
The numBeepSound parameter can take one of the following values:
numBeepSound Description
-1 Standard Beep (default, no sound card required)
64 System
78 System Exclamation
16 System
32 System Question
0 System Default
ViewScript Example
This ViewScript example causes a system exclamation sound:
Beep 78

Active Scripting Example


This sample is the same as above, written in VBScript.
View.Beep 78

See Also
PlaySound
View Scripting Functions Video/Sound

PlaySound
Plays a specified sound file (.WAV). Your system must be equipped with a
sound card and appropriate drivers.
Supported by: Windows PC and QuickPanel View/Control targets (see note).
Note: QuickPanel View/Control hardware does not support this function. You can still include it
in your scripts, but it will do nothing. If you want the target to emit an audible sound as a warning,
use Beep.

Active Scripting syntax


View.PlaySound strWaveFile

ViewScript syntax
PlaySound strWaveFile

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strWaveFile strWaveFile String expression indicating the path and
file name to the sound file to be played.
Use either a literal string or a STRING
variable.

Return Value
None

Comments
Can be used in conjunction with alarms or critical warning messages
displayed on screen.

ViewScript Example
This ViewScript example plays the alarm sound wave followed by a critical
alarm message on screen.
PlaySound "alarm.wav"
Message "Critical Alarm"
Active Scripting Example
This sample is the same as above, written in VBScript.
View.PlaySound "alarm.wav"
View.Message "Critical Alarm"

See Also
Beep
View Scripting Functions

Web script functions

The following Web functions are available:

Function Description
PanelToBitmap Creates a bitmap image of a panel.
PanelToJPEG Creates a JPEG image of a panel.
SendEmail Sends an e-mail to a specified list of recipients.
RollOverDocument Causes a custom document to generate its next instance
based on the original template, instead of the last
document.
View Scripting Functions Web

PanelToBitmap
Creates a bitmap image of a panel.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.PanelToBitmap strPanelName, strFileName

ViewScript syntax
PanelToBitmap panName, strFileName

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strPanelName panName The name of a panel. The panel can be
visible, hidden, or closed.
strFileName strFileName Name and/or path of the created bitmap.
If no path is given, the project path is
used. Can be either a literal or a STRING
variable.

Return Value

0: Error; the bitmap could not be created and/or written to file.


1: Success
Note: Alarm Objects and Chart Objects will be omitted from the generated bitmap of the panel.

Comments
This function cannot generate a bitmap larger than the pixel dimensions of
the HMI's screen. For example, calling PanelToBitmap with a 400 x 300 pixel
panel on a 6" QuickPanel View/Control unit (whose screen dimensions are
320 x 240) generates a bitmap of 320 x 240 pixels.

ViewScript Example
The following ViewScript example creates a bitmap of the 'MyPanel' panel,
and stores it as 'MyPanel.bmp' at the location specified in the path:
MyPanelToBitmapStatus := PanelToBitmap MyPanel,
"c:\ViewRuntime\WebDocs\MyPanel.bmp"

Active Scripting Example


This sample is the same as above, written in VBScript.
MyPanelToBitmapStatus.Value = View.PanelToBitmap ("MyPanel",
"c:\ViewRuntime\WebDocs\MyPanel.bmp")

See Also
PanelToJPEG
View Scripting Functions Web

PanelToJPEG
Creates a JPEG image of a panel.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.PanelToJPEG strPanelName, strFileName

ViewScript syntax
PanelToJPEG panName, strFileName

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strPanelName panName The name of a panel. The panel can be
visible, hidden, or closed.
strFileName strFileName Name and/or path of the created JPEG. If
no path is given, the project path is
used. Can be either a literal or a STRING
variable.

Return Value

0: Error; the JPEG could not be created and/or written to file.


1: Success
Note: Alarm Objects and Chart Objects will be omitted from the generated JPEG of the panel.

Comments
This function cannot generate a bitmap larger than the pixel dimensions of
the HMI's screen. For example, calling PanelToBitmap with a 400 x 300 pixel
panel on a 6" QuickPanel View/Control unit (whose screen dimensions are
320 x 240) generates a bitmap of 320 x 240 pixels.

ViewScript Example
The following ViewScript example creates a bitmap of the 'MyPanel' panel,
and stores it as 'MyPanel.jpg' at the location specified in the path:
MyPanelToJpegStatus := PanelToJpeg MyPanel,
"c:\ViewRuntime\WebDocs\MyPanel.jpg"

Active Scripting Example


This sample is the same as above, written in VBScript.
MyPanelToJpegStatus.Value = View.PanelToJpeg ("MyPanel",
"c:\ViewRuntime\WebDocs\MyPanel.jpg")

See Also
PanelToBitmap
View Scripting Functions Web

RollOverDocument
Forces specified custom web documents in a specified folder to generate its
next instance based on the original template, instead of the last document.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.RollOverDocument strDestinationFolder

ViewScript syntax
RollOverDocument strDestinationFolder

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strDestinationFolder strDestinationFolder The folder containing the template
file 'document.html' and all other
document source files.

Return Value

0: Error
1: Success

Comments
In a Custom Web Document, nesting tags inside <TCPRecord></TCPRecord>
tags causes subsequent instances of the document to retain existing values
inserted by the tags and append new values to them. Rolling over a
document means that when the next instance of the document is generated,
the list of previous values is not retained—only subsequent values will appear
on the web document.
Typically, web documents are rolled over at a frequency indicated by the
Custom Web Document property 'Roll Over Period'. The RollOverDocument
function forces the web document to roll over immediately, temporarily
overriding this setting.
If 'Roll Over Period' is set to Manual, the web document will only roll over
when RollOverDocument is called.
Note: If RollOverDocument is called in a script that runs periodically at a higher frequency than the
'Roll Over Period' property, then 'Roll Over Period' is effectively ignored. For example, if 'Roll Over
Period' is set to 1 hour and RollOverDocument is called in a script that executes every minute, then
web documents in strDestinationFolder have an effective 'Roll Over Period' of 1 minute.

ViewScript Example
The following ViewScript example causes the next instance of the custom web
document "Room Temperature" to base itself on the original template instead
of the previously generated instance.
MyRollOverDocument := RollOverDocument "RoomTemperature"

Active Scripting Example


This sample is the same as above, written in VBScript.
MyRollOverDocument.Value = View.RollOverDocument ("RoomTemperature")

See Also
PanelToBitmap, PanelToJPEG, TCPRecord
View Scripting Functions Web

SendEmail
Causes an e-mail message to be sent to a specified recipient or list of
recipients.
Supported by: Windows PC and QuickPanel View/Control targets

Active Scripting syntax


View.SendEmail strVarStatusName, strServer, strTo, strFrom,
strSubject, strBody [, strAttachmentPath]

ViewScript syntax
SendEmail varStatus, strServer, strTo, strFrom, strSubject, strBody [,
strAttachmentPath]

Parameters (see Naming Conventions)


Active Scripting ViewScript Description
strVarStatusName varStatus The name of a Machine Edition DINT
variable to contain the current status of
the SendEmail operation. For a table of
values, see Status Values below.
strServer strServer String expression containing the name
of the e-mail (SMTP) server through
which the message should be sent.
Typically, this is the name of a
computer on the network.
Note: If your system uses a firewall, port 25 must
be open for SMTP e-mail communications to work.

strTo strTo String expression containing the e-mail


addresses of the recipients. You can
enter multiple e-mail addresses
(separating them with semicolons), but
you must enter the full e-mail address
rather than an alias. This parameter
can have a maximum of 255
characters.
strFrom strFrom String expression containing the e-mail
address of the sender. This address will
appear in the "From:" box to the
message's recipients. This parameter
can have a maximum of 255
characters.
strSubject strSubject String expression containing the
Subject heading for the message. This
parameter can have a maximum of 255
characters.
strBody strBody String expression containing the text of
the message.
strAttachmentPath strAttachmentPath (Optional) String expression containing
the file name to a single file that you
can include as a MIME attachment with
the message. The maximum length of
the file is 1-MB.
Tip: If no path name is included, the file is
assumed to be in the project's runtime directory.
This makes it easy to send things like the last
alarm log file.

Return Value
This function returns an integer indicating one of the following results. The
status of the SendEmail operation is also stored in the variable indicated by
varStatus.
Note: Since the SendEmail operation takes place in a separate process or thread, the function will
return almost immediately. The varStatus variable contains the current status of the separate
SendEmail operation.

Return Value Description


0 The SendEmail operation was successfully initiated.
An unknown error occurred while trying to initiate the
-1
SendEmail operation.
-2 The thread for sending the SendEmail could not be created.
An invalid status variable was indicated and the SendEmail
-3
operation was not initiated.
varStatus codes Description
0 The message was successfully sent.
The SendEmail operation is in progress. The message has
1
not been sent, but no errors have yet occurred.
-1 The SendEmail operation failed for an unknown reason.
The e-mail (SMTP) server specified in strServer could not
-2
be found.
The e-mail (SMTP) server specified in strServer was found,
-3
but a connection could not be established.
The attachment specified in strAttachmentPath could not
-4
be accessed.
The runtime computer or unit could not create a new
-5
system process to start the SendEmail operation.
-6 The variable specified in varStatus is invalid.
-7 The sender e-mail address specified in strFrom is invalid.
The list of recipient e-mail addresses specified in strTo is
-8
invalid.

Comments
This function starts a separate process or thread to perform the SendEmail
operation. You can track the progress of the SendEmail operation by looking
at the value of the variable specified in varStatus.
When using this function in an Active Scripting language (such as VBScript),
names of all items and variables in parameters must be written as string
expressions. Also, strVarStatusName cannot refer to a variable that is locally
defined in VBScript with a DIM statement.

ViewScript Example
The following ViewScript example sends an e-mail reminder (whose text is
stored in strText using the StringCopy function) to John Smith to turn the
system off for the weekend. The status of the e-mail operation will be
available in the varStatus variable.
StringCopy strText, "This message is being sent because you have not
turned off the system for the week. Please also ensure that you fill
out the Project Time Allocation form as soon as possible. Thank
you."
MySendEmailStatus := SendEmail iMyStatus, "gefWebServer1",
"john.smith@myCompany.com", "system@myCompany.com", "WARNING: system
left still active", strText

Active Scripting Example


This sample is the same as above, written in VBScript.
strText.Value = "This message is being sent because you have not
turned off the system for the week. Please also ensure that you fill
out the Project Time Allocation form as soon as possible. Thank
you."
MySendEmailStatus.Value = View.SendEmail (iMyStatus.Name,
"gefWebServer1", "john.smith@myCompany.com", "system@myCompany.com",
"WARNING: system left still active", strText.Value)

You might also like