Definition of user procedures
In OWBasic it is possible to define user procedures.
User procedures and functions must always be defined at the start of the program. The main program always begins after that.
A procedure definition begins with the procedure heading and ends with the keyword ENDP.
PROC test A, B#, VAR C
<statements>
ENDP |
The procedure heading begins with the keyword PROC, followed by the name of the procedure and the parameter list.
The parameter list describes the parameters of the procedure.
Variables used within the procedure are local, i.e., outside of the procedure they are unknown.
It is possible to assign default values to the parameters; if the procedure is called without a default parameter, the compiler implicitly assigns the default value. Default values can also be pointers.
Example:
PROC clearscreen mode%=1
CLS mode
ENDP
PROC my_messagebox text$, caption$="", time#=0.0
msgbox text, caption, time
ENDP
PROC memory_size var size%=#NULL
IF &size THEN
FLASHSIZE size, dummy
ENDIF
ENDP |
If a parameter has a default value, the following parameters must also have a default value.
The call of user procedures takes place as with builtin procedures by means of the name. A user defined procedure is used, even if also a builtin procedure with the same name exists.
Example 1: Value parameter
PROC printxy x,y: ! Procedure that outputs coordinates
PRINT "("; x; ","; y; ")"; : ! Formatted output
ENDP
x=5: y=7: ! These variables do not have to do anything with
! the procedure parameters.
printxy x-4, y+6: ! Example-Call |
Example 2: Variables-Parameter
PROC myinc VAR n: ! Procedure similar to the builtin INC
n=n+1
ENDP
i=4
myinc i : ! Example-Call
PRINT i : ! output is 5 |
|