Procedure Block with Parameters

More Blocks

Description

Procedure Blocks can be made more versatile with parameters. Parameters provide information to a procedure that can influence its behavior. In the example below the number of blinks is provided as a numeric parameter. The loop is performed the number of times indicated by the "Count" parameter.

New Blocks can be defined in any Form Workspace available. The most commonly used form is the "Main" project form but others can be chosen from the drop down list in the upper left corner of the Blocks page. Parameters are associated with a specific procedure. Trying to use a parameter defined in one procedure anywhere besides that procedure is programming error.

Each list of blocks described as a procedure has a corresponding block listed under "More Blocks". This block can be used like any other block to perform all of the blocks in its list. Parameters can be filled in with explicit values:

Parameters can also be provided with other data expressions. The expression is evaluated once when the procedure block is performed. A copy of the expression value is provided to the procedure:

Using Procedure Block Parameters

Selecting the "More Blocks" category provides a "Define a Procedure Block" button.

Clicking this button presents an editor where a name can be provided:

After clicking "Ok" two new figures are shown:

On the right is a top style block where blocks can be attached to describe the desired actions. On the left is a block listed that can be used to invoke those actions somewhere else in the project. To add a parameter right click anywhere on the block to produce this local menu:

Selecting "Add Parameter" results in a prompt for the variable name and type:

After clicking "ok" both blocks change. The definition block now has a pre-constructed numeric expression in the parameter location with the chosen name. The block used in block lists now has a destination for numeric expressions.

To use a parameter drag the parameter from the procedure block to a destination in the procedure block list. The procedure definition is the source of the parameter and the parameter is immediately replenished allowing the parameter to be used as many times as needed within the procedure.

To change a parameter name right click on the parameter and select "Edit":

The parameter property editor is shown but only the name can be changed:

Parameter name changes are made to all of the parameters having that name in the procedure:

To remove a parameter right click on the procedure block and select "Delete Last Item":