This Global Procedures interface is used create a
library of VBScript
functions and sub-routines that can be called by any other
scripting interface in IWS. The procedures declared here are never
directly executed during runtime; they must be explicitly called by
another script.
CAUTION:
IWS will not prevent you from declaring two or
more functions with the same name. (This includes functions
imported from external files; see "Importing Functions from an
External File" below.) However, if you do, then your project may
behave unexpectedly during runtime. Make sure that all of your
functions are named correctly.
To use the Global Procedures interface:
- In the
Global tab of the Project
Explorer, right-click the Global
Procedures folder and choose Open from the shortcut menu.
Figure 1. Global
Procedures - Open option
The
Global
Procedures interface is displayed.
Figure 2. Global
Procedures Interface
- Declare your functions and sub-routines in the
interface. For example:
Option Explicit
'Keep the Option Explicit statement in the first line of this interface.
'Procedures with global scope can be implemented here
'Global variables are NOT supported in this interface
Sub MyMessage(message)
MsgBox(message,0)
End Sub
Function MyAdd(number1, number2)
MyAdd = number1 + number2
Call MyMessage("The sum is" & MyAdd & ".")
End Function
Note: You can
declare local variables within each procedure, but you cannot
declare global variables in this interface. In most cases, you
should use tags instead.
- Save your changes. The functions and sub-routines
are added to the Global Procedures folder in the Project Explorer.
Figure 3. Global
Procedures Tree
Organizing Procedures into
Subfolders
You can organize declared procedures into subfolders
within the Global Procedures folder. To organize procedures:
- In the Global Procedures
interface, insert the following line before the procedures
that you want to group together:
'$region:foldername
…where
foldername
is the name of the subfolder. For example:
Option Explicit
'Keep the Option Explicit statement in the first line of this interface.
'Procedures with global scope can be implemented here
'Global variables are NOT supported in this interface
'$region:My Subroutines
Sub MyMessage(message)
MsgBox(message,0)
End Sub
'$region:My Functions
Function MyAdd(number1, number2)
MyAdd = number1 + number2
Call MyMessage("The sum is" & MyAdd & ".")
End Function
- Save your changes. The procedures are organized into
subfolders in the Project
Explorer.
Importing Functions from an External
File
You can also import functions from an external file
and add them to the Global Procedures folder. This is useful if you
have a library of existing functions that you want to reuse.
To import functions:
- Save and close all open screens and worksheets.
- Right-click the Global Procedures folder and then
choose Import… from the shortcut
menu.
The
Import - Global
Procedures dialog is displayed.
Figure 4.
Import – Global Procedures
dialog
- In the File field,
click Browse to open a standard
Windows file browser and select a global procedures file. (This is
a plain text file that has been saved with the .gis file extension.)
- Select Replace functions
if they already exist to overwrite functions in the Global
Procedures folder with functions imported from the file, if the
functions have the same names.
- In the Functions area, you can import
All functions from the global
procedures file (*.gis) or
Only selected functions.
- Click Import.
After the functions are imported, they should be
available in the Global
Procedures folder.