Declarations
Previous examples have illustrated how a subroutine is defined in a SDL Passolo Script Engine module. The Sub keyword declares the subroutine and it is followed by the name of the subroutine.
A list of parameters can be supplied in the parenthesis after the name of the subroutine. The statements that should be executed by the subroutine follow the sub declaration and the subroutine ends with an End Sub statement. The following shows the declaration of a subroutine:
Sub SubName()
[Statements]
End Sub
Functions can also be declared. As mentioned they need some arguments (in some cases none) and they return one value and one value only. Functions can be called from running subroutines or macros or can be call-back functions within Passolo. This allows you to design your own functions for some checks, that you perform often. The following example shows a declaration of a subroutine, and a function. The subroutine calls the function, and uses the return value in a display box.
Sub TryAdd()
MsgBox(Str$(AddNumbers(34, 21)))
End Sub
Function AddNumbers(NumOne As Integer, NumTwo As Integer)
AddNumbers = NumOne + NumTwo
End Function
The example also illustrates how the functions return their value. An internal variable in the function with the same name as the function holds the return value. The value of this variable is returned when the function exits.