1. Create subroutine parameters
1. Create subroutine parameters
Subroutines may contain passed parameters. Define parameters in the parameter table of the subroutine. The parameter must have a symbol name (up to 24 characters), read and write permissions, and data type, and can choose to fill in comments. A subroutine can have a maximum of 16 parameters.
The read-write permission field in the parameter table defines whether the parameter has read-write permission. Parameters with read permission will request a valid value from the outside world before the program starts running. Parameters with write permission are used to write the result value back to the incoming software component after the program is completed. The table below illustrates the read and write permissions for parameters.
| Read and write permissions | Description |
|---|---|
| IN | specifies a software component or constant whose value is passed into this parameter of the subroutine. If a software component (such as D0) is specified, the value of the specified position is passed into the subroutine. If the parameter is a data constant (K1234), the constant value is passed into the parameter. |
| OUT | Program execution is completed, and the result value is fed back to the specified software component. Constants are not allowed to be specified. |
| INOUT | Behavior that simultaneously considers both IN and OUT. |
Attention
Only when there is a passing behavior between the calling and called parties can it be called a parameter. The variables used for internal closure are called local variables.
The data type fields in the parameter table define the size and format of the parameters. The following table lists the parameter types.
| Data Type | Description |
|---|---|
| BOOL | This data type is used for single bit input and output. |
| WORD | Single word (2 bytes) integer. It doesn't matter whether there is a symbol or not, it should be distinguished when using specific instructions. |
| DWORD | Double word (4 bytes) integer. It doesn't matter whether there is a symbol or not, it should be distinguished when using specific instructions. |
| FLOAT | Single precision (4 bytes) floating-point number. |