Global Procedures

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.

CAUTION:
InduSoft Web Studio 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.

You can create as many Procedures worksheets as you want, and each worksheet can contain as many functions and sub-routines as you want.

To use the Procedures interface:
  1. 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
    Web Studio Help worksheet global procedures main Global Procedures

  2. 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.
  3. Save your changes. The worksheet is added to the Procedures folder in the Project Explorer.
    Figure 2. Procedure worksheets with declared functions
    Web Studio Help illus vbscript globalprocedures Global Procedures

Organizing procedures into sub-folders

If you have many procedures in a single Procedures worksheet, then you may choose to organize them into sub-folders. To organize procedures:
  1. In the Procedures folder, open the worksheet that you want to organize.
  2. 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  
  3. 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.

To import functions into a worksheet:
  1. Save and close all open screens and worksheets.
  2. 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
    Web Studio Help dialog globalprocedures import Global Procedures

  3. 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.)
  4. 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.
  5. 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.
  6. Click Import.

After the functions are imported, they should be displayed in the worksheet.

Password protect a worksheet

You can put a password on any of your Procedures worksheets to prevent them from being edited or analyzed by other users. To protect a Procedures worksheet:
  1. In the Procedures folder, right-click the worksheet and then click Password Protection on the shortcut menu. A Password Protection dialog is displayed.
  2. In the New Password box, type your password.
  3. In the Confirm Password box, type your password again.
  4. Click OK.

Once this is done, you will be prompted for the password whenever you attempt to open the worksheet.

Global Procedures