Professional Documents
Culture Documents
(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.)
● 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:
(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.)
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
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.
● 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 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.
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.
ViewScript syntax
ActiveXGetProperty ActivexObjectName, strPropertyName, varReturnVal
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
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.
ViewScript syntax
ActiveXInvokeMethod ActivexObjectName, strMethodName,
strParameters, varReturnValue
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
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.
ViewScript syntax
ActiveXSetProperty ActivexObjectName, strPropertyName, varSetVal
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
See Also
ActiveXGetProperty, ActiveXInvokeMethod
View Scripting Functions
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
ViewScript syntax
AlarmAck almobjName
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
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
ViewScript syntax
AlarmClear almobjName
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
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
ViewScript syntax
AlarmClearAll almobjName
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
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
ViewScript syntax
AlarmFilter almobjName [, strNewFilter]
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.
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"
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
ViewScript syntax
AlarmFirst almobjName
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
ViewScript syntax
AlarmGroupCount almgrpName
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
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
ViewScript syntax
AlarmGroupCountAll [AlmgrpName]
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):
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
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
ViewScript syntax
AlarmGroupEnable AlmgrpGroupName, numAlarmParameter,
numNewValue
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
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
ViewScript syntax
AlarmGrpAck AlmgrpGroupToAck [, numSkipAckPrompt]
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
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
ViewScript syntax
AlarmLast AlmobjName
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
AlarmNext
Selects the alarm immediately following the currently selected alarm in an
Alarm Display object.
Supported by: Windows PC and QuickPanel View/Control targets
ViewScript syntax
AlarmNext almobjName
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
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
ViewScript syntax
AlarmPgDn almobjName
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
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
ViewScript syntax
AlarmPgUp almobjName
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
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
ViewScript syntax
AlarmPrev almobjName
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
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
ViewScript syntax
AlarmPrint almobjName
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
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
ViewScript syntax
AlarmPriority almobjName [, numNewPriority]
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
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
ViewScript syntax
AlarmVarAck varToAck
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
See Also
AlarmAck, AlarmGrpAck
View Scripting Functions
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
ViewScript syntax
ChangeBitmap panName, strobjName, strBmpFileName
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.
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"
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
ViewScript syntax
TriggerInput varName, strInputString [, numLoLimit] [, numHiLimit] [,
usePasswordMask]
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
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 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
ViewScript syntax
ActivateApp strAppTitleOrClassName [, numSearchForClassFlag]
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
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
ViewScript syntax
AppExec strFileName [, numStartMode]
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:
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"
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
ViewScript syntax
AppHelp strHelpFile [, strSearchKey]
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"
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
ViewScript syntax
AppShow strAppTitleOrClassName, numShowMode [,
numSearchForClassFlag]
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
ViewScript Example
The following ViewScript example hides the TrendX application.
HideTrendX := 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.
ViewScript syntax
SendKeys strKeyString
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
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
ViewScript syntax
SendValue varValueToSend [, numDigits, numDecimals]
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
See Also
ActivateApp, AppExec, AppHelp, AppShow, SendKeys
View Scripting 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 (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.
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
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
ViewScript syntax
CSVCloseFile numFileHandle
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
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
ViewScript syntax
CSVGetNumFields numFileHandle
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
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
ViewScript syntax
CSVGetNumLines numFileHandle
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
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
ViewScript syntax
CSVGetValue numFileHandle, numLine, numField, varDataBuffer
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:
Note: If the data type of varDataBuffer is not one of those listed above, the field value is not
retrieved and CSVGetValue returns 0.
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
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
ViewScript syntax
CSVOpenFile strFileName [, strDelimiter]
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.
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", ","
See Also
CSVGetNumLines, CSVGetNumFields, CSVGetValue, CSVCloseFile
View Scripting 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
ViewScript syntax
FileCopy strSource, strDestination [, numFailIfExists]
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.
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
ViewScript syntax
FileDelete strFileName
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.
FileMove
Moves a file or files from one directory to another.
Supported by: Windows PC and QuickPanel View/Control targets
ViewScript syntax
FileMove strSource, strDestination [, numFailIfExists]
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.
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
ViewScript syntax
FileRename strOldName, strNewName
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"
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
ViewScript syntax
FileSetDemoMode numNewMode
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
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
ViewScript syntax
HttpCopy strSource, strDestination, varResult
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.
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
ViewScript syntax
HttpDelete strFile, varResult
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.
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
See Also
HttpCopy, FileDelete
View Scripting Functions File Management
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.
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.
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
ViewScript syntax
IniForceIniPath strPathName
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"
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
ViewScript syntax
IniReadNumber strFileName, strSectionName, strKeyName, numDefault
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.
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
ViewScript syntax
IniReadString strFileName, strSectionName, strKeyName, strVarString, strDefault
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.
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
ViewScript syntax
IniWriteNumber strFileName, strSectionName, strKeyName, numValue
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
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
ViewScript syntax
IniWriteString strFileName, strSectionName, strKeyName, strString
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
See Also
IniForceIniPath, IniReadNumber, IniWriteNumber, IniReadString
View Scripting 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.
ViewScript syntax
lbAddString lbWinName, strNewString
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"
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
ViewScript syntax
lbDeleteString lbWinName, strToDelete
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
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
ViewScript syntax
lbDeleteStringAtIndex lbWinName, numIndex
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
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
ViewScript syntax
lbEmpty lbWinName
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
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
ViewScript syntax
lbFillWithDirectory lbWinName, strPath
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"
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
ViewScript syntax
lbFindString lbWinName, strName
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 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
ViewScript syntax
lbFindStringExact lbWinName, strName
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"
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
ViewScript syntax
lbGetCount lbWinName
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
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
ViewScript syntax
lbGetCurSel lbWinName
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
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
ViewScript syntax
lbGetItemData lbWinName, numIndex
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
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
ViewScript syntax
lbGetSelString lbWinName, strVarStoreIn
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
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
ViewScript syntax
lbGetString lbWinName, numIndex, strVarStoreIn
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
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.
ViewScript syntax
lbInsertString lbWinName, strNewString, numAtIndex
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
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
ViewScript syntax
lbSelectString lbWinName, strToSelect
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
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
ViewScript syntax
lbSetCurSel lbWinName, numIndex
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
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
ViewScript syntax
lbSetItemData lbWinName, numAtIndex, numCookie
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
See Also
lbGetItemData, Working With List Boxes, Working With Combo Boxes
View Scripting 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:
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.
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
ViewScript syntax
LogCloseFile numFileHandle
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
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
ViewScript syntax
LogDate numFileHandle
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.
ViewScript Example
The following ViewScript example logs the date to the logging file 'FileOne':
MyDateStatus := LogDate FileOne
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
ViewScript syntax
LogElapsed numFileHandle [, 0]
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
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
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
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
ViewScript syntax
LogNewFile strFileName, [, numExtension]
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
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
ViewScript syntax
LogNewLine numFileHandle
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
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
ViewScript syntax
LogOpenFile strFileName [, numExtension]
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
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
ViewScript syntax
LogPrintString numFileHandle [, strString]
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"
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
ViewScript syntax
LogPrintValue numFileHandle, numValue [, numPrecision]
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
ViewScript syntax
LogSetUseComma numFileHandle [, numUseCommas]
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
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
ViewScript syntax
LogTime numFileHandle
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
See Also
LogDate, LogElapsed
View Scripting Functions
ChangeDeviceParameters
Change configuration for a device of a Modicon TCP/IP driver.
Supported by: Windows PC, QuickPanel View/Control targets
ViewScript syntax
ChangeDeviceParameters strDeviceName, strParameters
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.
ViewScript Examples
Example: The following example reconfigures the device of a Modbus TCP/IP
driver:
ChangeDeviceParameters "MyMBTCPIPDevice", "1.2.3.4 -O1 -I9 -P502"
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
ViewScript syntax
Message strMessageString [, numChooseButton]
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.
● In ViewScript, add a caret (^) before each quotation mark. For example,
to display the message Motors are "ON", use:
Message "Motors are ^"ON^"."
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
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
ViewScript syntax
Random numMinRange, numMaxRange
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
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
ViewScript syntax
ToggleDiscrete disvarVarToToggle
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
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.
ViewScript syntax
NetChangeServer strServerTargetName
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"
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.
ViewScript syntax
PanelClose [panName]
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
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.
ViewScript syntax
PanelHide [panName]
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
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
ViewScript syntax
PanelIconize [panName]
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.
ViewScript Example
The following ViewScript example iconizes the panel 'PanelOne':
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
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.
ViewScript syntax
PanelOpen [panName] [, numAtX, numAtY]
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
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.
ViewScript syntax
PanelPrint panName
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
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
ViewScript syntax
PanelRestore [panName]
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
ViewScript syntax
PanelShow [panName]
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
ScreenSelectObject
Moves the cursor selection to a specified graphical object.
Supported by: Windows PC targets only
ViewScript syntax
ScreenSelectObject strObjectName
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"
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
ViewScript syntax
ScreenSetCursorPos panName, numXoffset, numYoffset
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
See Also
ScreenSelectObject
View Scripting 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.
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.
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
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.
ViewScript syntax
Logon [strUser, strPassword]
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
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
ViewScript syntax
ComPortClose numPortNumber
Return Value
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
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
ViewScript syntax
ComPortFlush numPortNumber
Return Value
None
ViewScript Example
The following ViewScript example flushes out the characters in the buffers of
COM1.
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.
ViewScript syntax
ComPortGet numPortNumber, strvarDestination, numMaxNumChars,
numTimeoutInMs
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
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
ViewScript syntax
ComPortGetFile numPortNumber, strFileName, numMaxNumChar,
numTimeoutInMs [, strStartCode] [, strStopCode]
Return Value
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
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
ViewScript syntax
ComPortGetHex numPortNumber, strvarDestination, numMaxNumChars,
numTimeoutInMs
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
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
ViewScript syntax
ComPortOpen numPortNumber, strPortSettingsString
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.
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
ViewScript syntax
ComPortPut numPortNumber, strOutputString
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
ViewScript syntax
ComPortPutFile numPortNumber, strFileName [, FlagWaitForXoff]
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.
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"
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
ViewScript syntax
ComPortPutHex numPortNumber, strOutputString
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"
See Also
ComPortGetHex
View Scripting 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
ViewScript syntax
SPCAddval numArrayID, numNewValue
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
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.
ViewScript syntax
SPCClearArray numArrayID
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
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.
ViewScript syntax
SPCCreateArray numArraySize
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
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
ViewScript syntax
SPCDeleteArray numArrayID
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
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.
ViewScript syntax
SPCGetVal numArrayID, numIndex
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
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.
ViewScript syntax
SPCMax numArrayID
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
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.
ViewScript syntax
SPCMean numArrayID
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
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.
ViewScript syntax
SPCMedian numArrayID, numPercent
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
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.
ViewScript syntax
SPCMin numArrayID
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
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.
ViewScript syntax
SPCRange numArrayID
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
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.
ViewScript syntax
SPCRangeMean numArrayID, numGroupSize
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.
ViewScript syntax
SPCSamples numArrayID
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
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.
ViewScript syntax
SPCSaveToFile numArrayID, strFilename, strFileTitle
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.
ViewScript syntax
SPCStdDev numArrayID
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
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.
ViewScript syntax
SPCStdDevMean numArrayID, numGroupSize
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
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.
ViewScript syntax
SPCSum numArrayID
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
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.
ViewScript syntax
SPCVariance numArrayID
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
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.
ViewScript syntax
SPCVarianceMean numArrayID, numGroupSize
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
● 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
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.
● >> 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.)
● 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
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
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
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.
ViewScript syntax
dbConnect strConnectParams
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
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.
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
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
ViewScript syntax
dbEndSQL numSQLHandle
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
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
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
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.
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
ViewScript syntax
dbFirstRecord numSQLHandle
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
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
ViewScript syntax
dbGetRecordCount numSQLHandle
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
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
ViewScript syntax
dbGotoRecord numSQLHandle, numRecordNumber
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
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
ViewScript syntax
dbLastError numvarErrorCode, strvarErrorMessage
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
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
ViewScript syntax
dbLastRecord numSQLHandle
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
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
ViewScript syntax
dbNextRecord numSQLHandle
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
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
ViewScript syntax
dbPrevRecord numSQLHandle
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
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
ViewScript syntax
dbSQL strSQLStatement
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.
See Also
dbLastError, dbEndSQL
SQL Statements
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
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.
ViewScript syntax
ASCIIToDec strSource [, numBytes]
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
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
ViewScript syntax
CopyDateToString strvarDestination [, numFormat]
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:
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
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
ViewScript syntax
CopyTimeToString strvarDestination
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
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
ViewScript syntax
CopyUserToString strvarDestination
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
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.
ViewScript syntax
DecToASCII strvarDestination, numDec [, numBytes]
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
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
ViewScript syntax
HexStringFromNum strvarDestination, numSource [, numBytes] [,
reversedOrder]
● 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
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.
ViewScript syntax
StringCompare strString1, strString2 [, numCaseSensitive]
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"
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.
ViewScript syntax
StringConCat strDestination, strSource
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".
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
ViewScript syntax
StringCopy strDestination, strSource
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
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
ViewScript syntax
StringLength strString
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'.
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
ViewScript syntax
StringFromNum strvarDestination, numSource [, numDigits,
numDecimals]
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
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
ViewScript syntax
StringPos strPatternString, strSearchString, numCaseSensitive
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.
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
ViewScript syntax
StringToNum strSource [, numMode]
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
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
ViewScript syntax
SubString strVarDestination, strSource, numStartingAt, numMaxCount
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
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
ViewScript syntax
AssignIndiFromStr varIndirect, strvarReal [, numOffsetCount]
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
● 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
● 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
ViewScript syntax
AssignIndirect varIndirect, varDirect [, numOffsetCount]
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
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
ViewScript syntax
DeviceChangeDriver strDeviceName
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
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
GetDayOfYear
Retrieves the current day of the year as an integer.
Supported by: Windows PC and QuickPanel View/Control targets
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
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
ViewScript syntax
LoadRecipe strFileName [, numExtensionNumber]
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".
● 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.
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'.
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
ViewScript syntax
LogEvent strEventString
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.
ViewScript syntax
LogGroupEnable loggrpName, numLogState
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
ViewScript syntax
LogGroupPeriod loggrpName, numPeriodLength
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
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.
ViewScript syntax
RestartWindows numDontAskConfirm
Return Value
None
ViewScript Example
RestartWindows myRestartWin
RunCommand
Executes a Runtime command.
Supported by: Windows PC and QuickPanel View/Control targets
ViewScript syntax
RunCommand ModuleName, strFunctionString
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"
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
ViewScript syntax
SaveRecipe strTemplate, strFileName [, numExtensionNumber]
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.
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
ViewScript syntax
SetLanguage strLanguageName
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"
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
ViewScript syntax
SystemExit numDontAskConfirm
Return Value
None
ViewScript Example
SystemExit myConfirm
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
ViewScript syntax
ValidateRecipe strFileName, [numVarLineInError,]
[numExtensionNumber]
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.
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
If validateResult = 0 Then
View.LoadRecipe "recipe01.txt"
Else
View.Message "Bad recipe file!"
End If
See Also
LoadRecipe, SaveRecipe
View Scripting Functions
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
ViewScript syntax
TrendClear trnobjName
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
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
ViewScript syntax
TrendContinueDisplay trnobjName
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
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
ViewScript syntax
TrendEdit trnwinName
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
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
ViewScript syntax
TrendPauseDisplay trnobjName
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.
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
ViewScript syntax
TrendPrint trnobjName
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
TrendSetRange
Sets the range for a currently-displayed Trend object.
Supported by: Windows PC and QuickPanel View/Control targets
ViewScript syntax
TrendSetRange trnobjName, numNewMin, numNewMax
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
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
ViewScript syntax
TrendSetRate trnobjName, numNewRate
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
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
ViewScript syntax
TrendTrigger trnobjName
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
See Also
TrendPauseDisplay , TrendContinueDisplay
View Scripting 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
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
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.
ViewScript syntax
AviOpen strAviFile, numXPos, numYPos, numWidth, numHeight
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
See Also
AviClose, AviPause, AviPlay, AviRewind
View Scripting Functions Video/Sound
AviPause
Temporarily stops a playing AVI multimedia file.
Supported by: Windows PC targets
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
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
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
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
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.
ViewScript syntax
PlaySound strWaveFile
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
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
ViewScript syntax
PanelToBitmap panName, strFileName
Return Value
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"
See Also
PanelToJPEG
View Scripting Functions Web
PanelToJPEG
Creates a JPEG image of a panel.
Supported by: Windows PC and QuickPanel View/Control targets
ViewScript syntax
PanelToJPEG panName, strFileName
Return Value
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"
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
ViewScript syntax
RollOverDocument strDestinationFolder
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"
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
ViewScript syntax
SendEmail varStatus, strServer, strTo, strFrom, strSubject, strBody [,
strAttachmentPath]
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.
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