Declaration
Declare a subroutine.
For ESL Internal Subroutines:
subroutine SUB_NAME ([TYPE1:ARG1_NAME [,TYPE2:ARG2_NAME]...])
For External Subroutines:
subroutine SUB_NAME ([TYPE1:ARG1_NAME [,TYPE2:ARG2_NAME]...])
[external name EXTERNAL_NAME]
library LIB_NAME
SUB_NAME
The identifier for the subroutine.
TYPEn
One of the following: integer, string, boolean, float, or structure STRUCTDEF_NAME (where STRUCTDEF_NAME is the identifier for a previously defined structure type).
ARGn_NAME
A descriptive name for the argument. This is a placeholder, so it does not need to be a variable in the program. However, if TYPEn is structure STRUCTDEF_NAME, then ARGn_NAME must not be the identifier for a previously declared structure variable.
EXTERNAL_NAME
A string value that is the external name of the function, if different from SUB_NAME. EXTERNAL_NAME can be used to create multiple aliases for external subroutines, and can be used to call subroutines that are exported only by ordinal. See the "Description" section for more information.
library LIB_NAME
Identifier for a dynamic link library.
Description
You must declare a subroutine before defining or referencing it. However, once you declare an ESL internal subroutine, you can reference it before you define it.
ESL internal and external subroutines can take a maximum of 13 arguments.
An external subroutine must be declared before it is referenced.
To call an external subroutine that is not exported by name, EXTERNAL_NAME should be a quoted string containing an at character (@) followed by the ordinal number, in decimal. To call the subroutine at ordinal 1, EXTERNAL_NAME should be "@1".
Be aware that Windows does not return an error if ESL tries to access a non-existent function by ordinal. ESL will try to call the non-existent function, most likely leading to a General Protection Fault (GPF).
Libraries provided with ESL have include files that contain declarations for all the external subroutines in the library.
You can declare an ESL internal subroutine or an external subroutine that takes a structure variable as an argument. Structures allow you to group variables under one name as a convenient way of passing arguments to internal and external subroutines. Structures also allow you to call external routines that expect a structure as an argument. For more information, see the Programming Guide.
If the type and number of arguments in the ESL subroutine declaration and the definition are not the same, a compile-time error is generated when ESL reads the definition.
If there is an ESL subroutine declaration but no definition, a runtime error is generated when the subroutine is called.
If an external subroutine is called but never declared, an error is generated at compile-time.
Example
# ESL subroutine declaration
subroutine DrawGraph (string:RegionName,
string:GraphType)
# Subroutine definition. Can appear anywhere in the
# program after the declaration.
subroutine DrawGraph (string:RegionName, string:GraphType) is
copy RegionName_SV to GRegion # Region used by BGraph module
switch (GraphType_SV) is
case char col 1 "Bar" is
action GBars
...
case char col 1 "Line" is
action GLines
default is action GBars
end switch
subroutine MIN (float:ArrayIn, float:Minimum)
library "mathlib"
See Also
function Declaration
structure Variable Declaration
structure is Type Definition
subroutine is Definition