Parameters

 

To specify the parameter role in the procedure, you have the ability to typecast the parameter in the procedure declaration.

For example, to use numeric values only, you have the ability to declare:

 

PROCEDURE Multiply10(P is numeric)

 

The WLanguage code of the procedure is:

 

PROCEDURE Multiplication(Nb1 is int, Nb2 is int)

MyResult is int

MyResult = Nb1 * Nb2

RESULT MyResult

 

The WLanguage code used to call the procedure is:

res is int

res = Multiplication(10, 50)

// Res is equal to 500

 

How to use the parameters?

By default, passing parameters in WLanguage is performed by reference (or by address). The parameter in the procedure represents (references) the variable passed during the call.

Therefore, when a statement of the procedure modifies the parameter value, the value of the variable corresponding to this parameter is modified.

Example:

The WLanguage code of the procedure is:

PROCEDURE Test_Reference(P1)

P1 = P1 * 2

 

To avoid modifying the value of the variable corresponding to the parameter, the parameters must be passed by value.

Passing parameters by value allows you to handle a copy of parameter value. If the procedure code modifies the variable value, the value of the variable corresponding to the parameter is not modified.

To force a parameter to be passed by value to a procedure, the LOCAL keyword must be used in front of the parameter name in the procedure declaration. This keyword indicates that the following parameter will not be modified by the procedure.

Example:

The WLanguage code of the procedure is:

PROCEDURE Test_value(LOCAL P1)

// Local indicates that the parameter will be passed by value

P1 = P1 * 2