It's a routine that is local to the object in which it is defined. That is to say, it's a block of code identified with a name. From there, it can be run within the object (and only there) using the Do command.
In this way, if you need to run the same block of code from several places of the object, it can be written once and invoked from various locations.
Subroutines are defined using the Sub command.
Where are they created? In the objects that accept procedural programming in any of their sections:
- They don't support passing parameters; therefore, to exchange data you use variables that are global to the objects.
- They are not context-sensitive (beyond variables and object parameters). This has some consequences:
- In the programming defined in a subroutine, using "loose" attributes and expecting them to have the same value they had when making the call is not recommended (the subroutine can be invoked from several places within the object). Therefore, before calling the subroutine it is recommended that you assign these attributes to variables and use these variables in the subroutine.
- If a subroutine contains For Each or New commands:
- They won't be nested in For Each or New commands from where the subroutine was called, which means that there won't be any inferences or filters.
- They won't be nested in implicit For Each commands corresponding to grids or the fixed part of Web Panels, Panels, Work Panels.
If in the Source of a Procedure or in the Events section of any of the above objects you have a For Each command that calls a subroutine:
and you have the 'Something' subroutine defined as follows:
The For Each command present in the subroutine will not be nested with the For Each command from where the subroutine was called. They will not be related, meaning that there won't be any automatic filters or inferences of any kind.
Note: The attributes used in an object will be global variables in the corresponding generated program. Therefore, if a certain attribute takes value in a certain section of an object, and later a subroutine that also assigns a value to the same attribute is called, when returning from the invoked subroutine and querying the attribute's value it will have the value assigned in the subroutine.