Florence nightingale
Subroutines and functions enable you to divide a program into smaller parts. A subroutine or function is a named group of statements, constants, variables and other declarations that perform a particular purpose. A function is identical to a subroutine in every respect, with the one exception: it can return a single value to the calling program. Swordfish subroutines and functions are non re-entrant, that is, you cannot make recursive subroutine or functions calls.
Parameters
The compilers default parameter passing mechanism is by value or ByVal. Passing by value means that a local copy of the variable is created, and the subroutine or function operates on a copy. If your …ver más…
For example, given the declaration sub MySub(byref pValue as word) end sub
then an error 'cannot be passed by reference' message is generated when any of the following calls are made,
MySub(10) MySub(Index * Index)
Remember, passing by reference forces the compiler to pass the RAM address of a variable, allowing it to be changed from within a subroutine or function. Constants or expressions do not have RAM addresses associated with them, and so cannot be used if a parameter argument is expecting pass by reference. If your subroutine or function parameter declaration is likely to be passed a constant or expression, then you must always pass by value. When a parameter is passed by value, it is sometimes useful to initialize the argument with a constant. For example, sub Print(pStr as string, pTerminator as string = #13 + #10) USART.Write(pStr, pTerminator) end sub
The formal parameter pTerminator has a default value of #13#10, which corresponds to a carriage return, line feed pair. If the subroutine Print() is called without a pTerminator argument value,
Print("Hello World")
then pTerminator will default to #13#10 when USART.Write() is called. If you wish to explicitly override the formal parameter default, then call your subroutine with the required value, like this
Print("Hello World", null)
Here, pTerminator is set to the null terminator when USART.Write() is called. It should be noted that you can only assign constants if the