figure 5-1
You must start your PROCEDURES with the PROCEDURE keyword. Next it must have a name that doesn't appear in another PROCEDURE or FUNCTION. Note that DCAL has many internal PROCEDURES and FUNCTIONS and you should not use any of their names either.
A PROCEDURE may take parameters (<optional_params>) These parameters are variables that will be used in some way by the PROCEDURE. Your PROCEDURES may declare variables that they need to do their work.
Variables used only in and seen only within a PROCEDURE are called local variables. The use of local variables is optional. The keyword BEGIN tells the compiler here is where the actual work starts.
Finally the PROCEDURE ends with the keyword END followed by the name of the procedure. The name must match at both the PROCEDURE declaration and the END of the PROCEDURE.
The syntax for a FUNCTION is:
figure 5-2
A FUNCTION is similar to a PROCEDURE. It must have a unique name <function_name>. It begins with the FUNCTION keyword and ends with the END keyword followed by the name of the FUNCTION. It may declare local variables and it needs the BEGIN keyword before the <statement(s)> section. A FUNCTION may take parameters.
The key difference is that a FUNCTION will return a value. What this means is that a FUNCTION will evaluate to one of DCALs TYPES. A FUNCTION may have multiple RETURN statements in its code however only the first one that is encountered will be executed. Once the program hits a RETURN statement the <return_value> is sent back to the routine that called the FUNCTION and the FUNCTION terminates. The difference between PROCEDURES and FUNCTIONS are subtle but important.
Thank you for printing this page. Please feel free to contact us for further assistance. You can call our sales department at +1 (800) 394-2231, Monday through Friday from 8:00 a.m. to 5:00 p.m. Eastern time or send an e-mail message to info@datacad.com.