This Procedures interface is used create a library of VBScript functions and sub-routines that can be called by any other scripting interface in InduSoft Web Studio. The procedures declared here are never directly executed during runtime; they must be explicitly called by another script.
You can create as many Procedures worksheets as you want, and each worksheet can contain as many functions and sub-routines as you want.
- In the Global tab of the Project Explorer, do one of the following:
- To edit the default Procedures worksheet, open the Procedures folder and then double-click Main Procedures; or
- To create a new Procedures worksheet, right-click the Procedures folder and then click Insert on the shortcut menu.
Either way, the worksheet is opened for editing.Figure 1. Main Procedures worksheet
- 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 FunctionNote: 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 worksheet is added to the Procedures folder in the Project Explorer.
Figure 2. Procedure worksheets with declared functions
Organizing procedures into sub-folders
- In the Procedures folder, open the worksheet that you want to organize.
- In the worksheet, insert the following line before the procedures that you want to group together:
'$region:foldername…where foldername is the name of the sub-folder. For example:
'$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 sub-folders under the Procedures worksheet in the Project Explorer.
Import functions from an external file
You can also import functions from an external file and add them to a Procedures worksheet. This is useful if you have a library of existing functions that you want to reuse.
- Save and close all open screens and worksheets.
- In the Procedures folder, right-click the Procedures worksheet into which you want to import functions, and then click Import on the shortcut menu.
The Import – Global Procedures dialog box is displayed.Figure 3. Import – Global Procedures dialog box
- To the right of the File box, click Browse. A standard Windows file browser is displayed. Use it to locate and select a Procedures worksheet 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 worksheet with functions imported from the file, if the functions have the same names.
- In the Functions area, do one of the following:
- Click All to import all functions from the file; or
- Click Only to import only selected functions from the files, and then select those functions in the list.
- Click Import.
After the functions are imported, they should be displayed in the worksheet.
Password protect a worksheet
- In the Procedures folder, right-click the worksheet and then click Password Protection on the shortcut menu. A Password Protection dialog is displayed.
- In the New Password box, type your password.
- In the Confirm Password box, type your password again.
- Click OK.
Once this is done, you will be prompted for the password whenever you attempt to open the worksheet.