Built in Functions
Built in Functions
Built in Functions
.
Summary
File manipulation is often an important function in an HMI/SCADA application. Loading or storing a Batch or Recipe
files, accessing historical data, archiving or purging older files are among the examples where file manipulation is
required. As discussed in this Application Note, InduSoft Web Studio (IWS) provides several built-in functions to
access Collections (groups of folders or files), Folders (directories) and individual Files. Application Note AN-00-0006
will discuss the use of VBScript’s FileSystemObject object, included in VBScript’s runtime library, to access
Collections, Folders and Files. Either approach can be used, and the selection is often merely the developer’s
preference.
IWS built-in functions can be called from a Math Worksheet script or from a VBScript code segment. Examples of both
will be shown.
Valid
GetLine (“C:\IWS\Readme.txt”, “Hello”, “StrMyLine”)
GetLine (“C:\IWS\Readme.txt”, “Hello”, “StrMyLine”, 1)
GetLine (“C:\IWS\Readme.txt”, “Hello”, “StrMyLine”, “”, “NumOverFlow”)
Invalid
GetLine (“C:\IWS\Readme.txt”, “Hello”, “StrMyLine”, , “NumOverFlow”)
GetLine (“C:\IWS\Readme.txt”, “Hello”, “StrMyLine”, “”, “NumOverFlow”)
C. If the Command syntax refers to a Tag[Name] or OptTag[Name] parameter, usually enclosed in double
quotations, this Tag must be an IWS tag. It cannot be a VBScript variable or an Expression.
D. VBScript variables can only be used in a VBScript code segment, located in a Command Object, Background
Script, Graphic Script, Screen Script, or a Global Procedure. VBScript variables are not accessible from an
IWS Math Worksheet or other IWS native objects. InduSoft places limitations on the scope (accessibility) of
VBScript variables from one code segment to another. Please refer to the InduSoft Web Studio Users Manual
for additional details.
E. When used in a VBScript code segment, the $ symbol is used as a prefix to signify an IWS built-in (native)
function. Likewise, the $ symbol is used as a prefix to signify an IWS tag. A full description of these built-in
functions is contained in Appendix A of the InduSoft Web Studio Users Manual,
2
Built-in Functions
©Copyright InduSoft Systems LLC 2006
3
Built-in Functions
©Copyright InduSoft Systems LLC 2006
Drive Functions
IWS provides very limited Drive functions. The only function provided at this time is to check the free space (bytes)
available on a specified disk drive.
InfoDiskFree (strDisk)
Function
This function returns the free disk space on a specified disk
Parameters
strDisk is an IWS string tag, expression or VBScript variable containing the name of the disk to be checked
Note: You must use this function in VBScript in order to use a VBScript variable as a parameter
Return Value
Returns the free space on the disk in bytes
Example IWS Usage
Tag Expression
StatFlag InfoDiskFree(“C”)
Example VBScript Usage
Dim MyDisk, FreeSpace
MyDisk = “C”
FreeSpace = $InfoDiskFree(MyDisk)
4
Built-in Functions
©Copyright InduSoft Systems LLC 2006
Folder Functions
IWS uses the term Directory (or DIR) for a folder, although the meaning is interchangeable. The Directory functions
Note that all of the Folder functions work in either a Windows XP/2000/NT or Windows CE runtime environment.
However, these functions were not intended to run on Web Thin Client (unless otherwise noted). When a Web Thin
Client executes a function that calls a Folder function, the Folder function executes on the Server station.
Folder functions can be used in conjunction with various System Information functions. One example is to create a
folder which has the current date built-in to the folder name. This folder can then used to set the History path for the
current application (see SetAppHSTPath function).
5
Built-in Functions
©Copyright InduSoft Systems LLC 2006
6
Built-in Functions
©Copyright InduSoft Systems LLC 2006
DirLength (strDirectory)
Function
This function returns the size (in bytes) of the Directory specified. This function may take several seconds to return
a value, so the use of this function must be done with caution.
Parameters
strDirectory is an IWS string tag, expression or VBScript variable containing the name and file path of the
directory.
Note: You must use this function in VBScript in order to use a VBScript variable as a parameter
Return Value
The Returned Value has one of 3 possible values:
-2 Directory does not exist
-1 Invalid Parameters
>=0 Size (in bytes) of the files and subfolders in the directory
Example IWS Usage
Tag Expression
StatFlag DirLength (“C:\MyApp\Temp”)
Example VBScript Usage
Dim StrDir, RetVal
StrDir = “C:\MyApp\Temp” ‘Specifies the Directory
RetVal = $DirLength (StrDir) ‘Call the Directory Length function
If RetVal >-1 Then MsgBox “Directory Length = ” & RetVal & “ Bytes”
7
Built-in Functions
©Copyright InduSoft Systems LLC 2006
8
Built-in Functions
©Copyright InduSoft Systems LLC 2006
FindPath (strDir)
Function
This function verifies whether a directory exists or not.
Parameters
strDir is an IWS string tag, expression or VBScript variable containing the name and file path of the directory to be
verified.
Note: You must use this function in VBScript in order to use a VBScript variable as a parameter
Return Value
The Returned Value has one of 2 possible values:
0 Path not found
1 Path found
Example IWS Usage
Tag Expression
StatFlag FindPath (“C:\MyApp\Temp”)
9
Built-in Functions
©Copyright InduSoft Systems LLC 2006
Parameters
strDirectory is an IWS string tag, expression or VBScript variable containing the name and file path of the
directory.
strMask is an IWS string tag, expression or VBScript variable that contains the mask of the files to be deleted
strDate is an IWS string tag, expression or VBScript variable containing the cut-off date. Files older than this date
will be deleted.
Note: You must use this function in VBScript in order to use a VBScript variable as a parameter
Return Value
The Returned Value is the number of files deleted.
10
Built-in Functions
©Copyright InduSoft Systems LLC 2006
“optstrTagFilesFound” is an optional IWS string tag array to receive the path and name of each file found. Array
index 0 will be blank. The first file found will be in the array index 1, the next file found will be in array index 2, etc.
This must be an IWS string tag array and cannot be an expression or VBScript Array.
optNumTimeOut is an optional IWS integer tag, expression or VBScript variable containing an integer value used
to set the timeout period in milliseconds for the operation.
Note: You must use this function in VBScript in order to use a VBScript variable as a parameter
Note: This File Function operates in a synchronous manner with other operations; i.e. other operations will not
progress until this operation is completed. Therefore, it is highly recommended to use the optNumTimeOut
parameter. Slow network transfer rates may also cause a problem. If a timeout occurs, the function returns a
value of -1. This does not cancel the copying procedure, but will allow the other IWS operations to proceed
and an internal process to finish the file copying will be created.
Return Value
The Returned Value is the number of files deleted.
-1 Timeout occurred
0 No files found
N Number of files found
11
Built-in Functions
©Copyright InduSoft Systems LLC 2006
strDirectory is an IWS string tag, expression or VBScript variable containing the name and file path of the directory
to be searched.
strMask is an IWS string tag, expression or VBScript variable that contains the mask of the files to be searched
numCgDir is an IWS integer tag, expression or VBScript variable that controls whether to allow changing of
directories. If the value is 0, a simple popup window will appear with a list of files in the directory that meet the
Mask criteria. If the value is <>0 then a Windows file dialog box will appear that allows the changing of directories.
With either window, the selected file (path and file name) will be stored in the SelTagFile tag.
Note: You must use this function in VBScript in order to use a VBScript variable as a parameter
Return Value
The Returned Value is the number of files deleted.
0 Successful
1 One of the parameters is not a string
2 The first parameter is not a valid tag name
3 The user cancelled the operation
12
Built-in Functions
©Copyright InduSoft Systems LLC 2006
File Functions
IWS has several built-in file functions that allow a developer to manipulate individual files at run-time. These File
Functions work for Windows XP/2000/NT and Windows CE runtimes, as well as for Thin Clients, unless otherwise
noted.
13
Built-in Functions
©Copyright InduSoft Systems LLC 2006
strTarget is an IWS string tag, expression or VBScript variable containing the path where the file(s) are to be
copied.
optNumTimeOut is an optional IWS numeric tag, expression or VBScript variable containing an integer to set the
timeout period in milliseconds for the operation.
Note: You must use this function in VBScript in order to use a VBScript variable as a parameter
Return Value
The Returned Value is the number of files deleted.
-1 Timeout occurred
0 Failed to copy file(s)
1 Successful
14
Built-in Functions
©Copyright InduSoft Systems LLC 2006
15
Built-in Functions
©Copyright InduSoft Systems LLC 2006
FileDelete (strFile)
This function deletes the specified file
Parameters
strFile is an IWS string tag, expression or VBScript variable containing the path and file name of the file to delete.
Note: You must use this function in VBScript in order to use a VBScript variable as a parameter
Return Value
The Returned Value is the number of files deleted.
0 Failed to delete file
>0 Size (in bytes) of the file deleted. This is an IWS type real
16
Built-in Functions
©Copyright InduSoft Systems LLC 2006
FileLength (strFile)
Function
This function returns the size of a file in bytes
Parameters
strFile is an IWS string tag, expression or VBScript variable containing the path and file name of the file.
Note: You must use this function in VBScript in order to use a VBScript variable as a parameter
Return Value
The Returned Value is the size of the specified file in bytes.
17
Built-in Functions
©Copyright InduSoft Systems LLC 2006
18
Built-in Functions
©Copyright InduSoft Systems LLC 2006
GetFileAttributes (strFile)
Function
This function reads the attributes of a specified file.
Parameters
strFile is an IWS string tag, expression, or VBScript variable containing the path and file name of the file from
which the attributes are read.
Note: You must use this function in VBScript in order to use a VBScript variable as a parameter
Return Value
The Returned Value is the number of files deleted.
-1 Error
1 Read-only
2 Hidden
4 System
16 Directory
32 Archive
128 Normal
256 Temporary
19
Built-in Functions
©Copyright InduSoft Systems LLC 2006
Return Value
Returns the date and/or time the file was last modified.
20
Built-in Functions
©Copyright InduSoft Systems LLC 2006
Returned values
0 Success
-1 Invalid number of parameters
-2 Invalid URL
-3 Internal Error
-4 Error connecting to the Web Server
-5 Error creating the destination local file
21
Built-in Functions
©Copyright InduSoft Systems LLC 2006
22
Built-in Functions
©Copyright InduSoft Systems LLC 2006
23
Built-in Functions
©Copyright InduSoft Systems LLC 2006
Return Value
There is no return value.
24
Built-in Functions
©Copyright InduSoft Systems LLC 2006
PrintSetup()
Function
This function opens the standard printer dialog box from the operating system. A default printer can be selected
and configured for print operations.
Parameters
No parameters
Return Value
There is no return value.
25
Built-in Functions
©Copyright InduSoft Systems LLC 2006
Miscellaneous Functions
The following functions are miscellaneous functions provided to manage IWS applications and tasks. Many of these
functions are special purpose in nature.
GetAppPath()
Function
This function returns the directory of the current application.
Note: InfoAppDir is a similar function. However, use of the GetAppPath() function is preferred as it
always returns a “\” at the end of the path, regardless of the operating system used.
Parameters
None
Return Value
Returns the directory of the current application as a string value. Can be stored in an IWS string tag or a VBScript
variable. A “\” is included at the end of the path (directory).
26
Built-in Functions
©Copyright InduSoft Systems LLC 2006
27
Built-in Functions
©Copyright InduSoft Systems LLC 2006
GetProductPath()
Function
This function returns the path where the IWS program files are located
Parameters
None
Return Value
Returns the path to the IWS directory as a string value. Can be stored in an IWS string tag or a VBScript variable.
28
Built-in Functions
©Copyright InduSoft Systems LLC 2006
29
Built-in Functions
©Copyright InduSoft Systems LLC 2006
Hst2TxtIsRunning()
Function
This function returns the status of the Hst2Txt function
Parameters
None
Return Value
-30 Cannot access dll function
-20 IndHst.dll was not found
-10 Cannot create Header file (.hdr)
-9 Invalid number of tag in the header information (0 > nTags > 250)
-8 Cannot read header information from HST file
-7 Invalid file type
-6 Cannot read file information from HST file
-5 Cannot create/open ASCII file
-4 Cannot open HST file
-3 File not found. There are no history files in the configured time interval for the group specified
-2 Reserved
-1 Last conversion process was executed properly
0 Hst2Txt is still running
30
Built-in Functions
©Copyright InduSoft Systems LLC 2006
InfoAppAlrDir()
Function
This function returns the Alarm directory for the current application.
Parameters
None
Return Value
Returns the Alarm directory for the current application as a string value. Can be stored in an IWS string tag or a
VBScript variable.
Example IWS Usage
Tag Expression
StrPath InfoAppAlrDir()
31
Built-in Functions
©Copyright InduSoft Systems LLC 2006
InfoAppDir()
Function
This function returns the path to the current application. This function is similar to the GetAppPath() function, with
the difference being that the InfoAppDir() function does not return a “\” at the end of the path when used in a
Windows XP/2K/NT runtime environment, while returning a “\” at the end of the path when used in a Windows CE
environment. The GetAppPath() function is newer and is the preferred function for consistency purposes..
Parameters
None
Return Value
Returns the directory of the current application as a string value. Can be stored in an IWS string tag or a VBScript
variable.
Example IWS Usage
Tag Expression
StrPath InfoAppDir()
32
Built-in Functions
©Copyright InduSoft Systems LLC 2006
InfoAppHstDir()
Function
This function returns the History directory for the current application.
Parameters
None
Return Value
Returns the History directory of the current application as a string value. Can be stored in an IWS string tag or a
VBScript variable.
33
Built-in Functions
©Copyright InduSoft Systems LLC 2006
34
Built-in Functions
©Copyright InduSoft Systems LLC 2006
SetAppAlarmPath (strPath )
Function
This function is used to set the Alarm path for the current application.
Note: this function is not supported on Thin Client environments.
Parameters
strPath is an IWS string tag, expression, or VBScript variable containing the new Alarm path for the current
application.
Note: You must use this function in VBScript in order to use a VBScript variable as a parameter
Return Value
There are no return values
Example IWS Usage
Tag Expression
SetAlarmPath (“C:\MyApp\Alarm”)
35
Built-in Functions
©Copyright InduSoft Systems LLC 2006
SetAppPath (strPath)
Function
This function sets the new path for an application. After this function is executed, IWS will look for all the
configuration files (screens, alarms, trends, database, events, web) in this new path. However, the existing tag
database will continue to be used.
Note: this function is only supported on Windows XP/2000/NT runtime environments.
Parameters
strPath is an IWS string tag, expression, or VBScript variable containing the file path to the application. If the
computer is on a network, you can use either //<IP address>/<Path> or //<Host Name>/<Path> syntax.
Note: You must use this function in VBScript in order to use a VBScript variable as a parameter
Return Value
0 Failed to set path
1 Succeeded in setting path
Example IWS Usage
Tag Expression
RtnVal SetAppPath (“C:\IWS\MyApp”)
36
Built-in Functions
©Copyright InduSoft Systems LLC 2006
SetAppHstPath (strPath)
Function
This function is used to set the History path for the current application.
Note: this function is not supported on Thin Client environments.
Parameters
strPath is an IWS string Tag, expression, or VBScript variable containing the new History path for the current
application.
Note: You must use this function in VBScript in order to use a VBScript variable as a parameter
Return Value
There are no return values
Example IWS Usage
Tag Expression
SetAppHstPath (“C:\MyApp\Hst”)
37
Built-in Functions
©Copyright InduSoft Systems LLC 2006
38