Procedures |
Procedures are functions and subroutines that you want to be accessible to other event scripts. The scope of the procedure (meaning where you can use it), depends on the type of procedure you are scripting.
Below is a list of tasks often performed and items often placed in the Procedures scripts:
User-Defined Functions and Subroutines: It is standard programming practice to place a section of computer code that needs to be run from multiple places into either a function or a subroutine. Placing them into the Procedures script lets them be called multiple times from multiple scripts.
Common Variables: To declare variables that will be accessible to all your event control scripts for a given data source, you can "dimension" them (using the Visual Basic "dim" statement) in the Procedures script. Alternatively, you can simply initialize variables and they will be automatically dimensioned for you. (We use the term "common variables" and not "global variables," because they can only be accessed by event control scripts associated with the same data source. For more information, refer to Defining "Global" Variables, below.)
Variable Initialization: Variables can be set to a starting value by inserting a line of Visual Basic code similar to
VariableName = value
into the Procedures script. Here, "VariableName" is the name of the variable to initialize and "value" is the value to initialize it to. Initialization in this manner lets you dispense with the previously mentioned dimensioning of variables, since Visual Basic will determine what variables are not yet dimensioned and do it for you automatically.
Any Other Initialization: Any other code you need to run in order to set anything up that any of your other scripts might need, such as opening or creating a log file, or perhaps checking for the preexistence of a file. Depending on your needs and/or preference, this code can be placed inside a function or subroutine in the Procedures script, or simply left as "naked" code and inserted as-is into script.
There are four types of procedures: Procedures for All Events, Procedures for Document Events, Procedures for Data Source Events, and Procedures for Transform Events.
Procedures for All Events: Contain functions and subroutines that are accessible to all the other event scripts in the document. You can also use the Procedures for All Events script to declare variables that can be accessed by any script in the document.
Procedures for Document Events: Accessed only by document-level event scripts.
Procedures for Data Source Events: Accessed by other event control scripts within the same data source.
Procedures for Control Events: Accessed only by event control scripts within the same data entry control.
Procedures for Transform Events: Accessed by the transform scripts in the events “OnProcessData” and/or “OnPostSerialize.” For more information, refer to Using the VBScript Transform.
Procedures can be used to declare variables that can be accessed by multiple scripts in your document. Variables that are global to an entire document (and therefore shareable by scripts for different objects within a document) can be defined in the Procedures for All Events script.
Related Topics