Function, Procedure, Return, EndFunc, EndProc
FUNCTION and PROCEDURE indicate that what follows is a subroutine. When used in a DEFINE CLASS command, these two commands indicate the code that follows is a method. RETURN indicates that control should return from a subroutine and may include a value to pass back to the calling program. ENDPROC and ENDFUNC are optional, signaling the end of their respective procedures and functions, but are weaker placeholders than RETURN.
Usage |
FUNCTION RoutineName [ ( LocalParameterList) ] PROCEDURE RoutineName [ ( LocalParameterList ) ] |
Usage |
RETURN [ eReturnValue ] [ TO MASTER ] [ TO FunctionName ] ENDFUNC ENDPROC |
Be aware that RETURN TO expects a literal procedure name—you'll need to use &lcProcName to macro-expand a variable procedure name. For an object method, you need to use only the method name and not the object designation—RETURN TO ReadEvents works, but RETURN TO oApp.ReadEvents bombs. Far worse, RETURN TO anywhere or RETURN TO &lcProcName will perform a RETURN TO MASTER if "anywhere" hasn't been declared or if the lcProcName isn't in the calling stack. We'd expect a syntax error instead. |
Example |
PROCEDURE CleanUp * Clean up after a program dies. SET SYSMENU TO DEFAULT CLOSE ALL CLEAR ALL ON KEY RETURN FUNCTION MakeName(cFirst, cMiddle, cLast) * Combine a first name, middle name and last name to * get one nicely formatted name. cMiddle may be omitted. * Sample call: ?MakeName("Tamar","E.","Granor") * ?MakeName("Ted",,"Roche") LOCAL cFullName IF TYPE("cFirst")<>"C" ; OR (TYPE("cMiddle")<>"C" AND TYPE("cMiddle")<>"L") ; OR TYPE("cLast")<>"C" RETURN "" ENDIF IF EMPTY(cMiddle) cFullName=TRIM(cFirst)+" "+TRIM(cLast) ELSE cFullName=TRIM(cFirst)+" "+TRIM(cMiddle)+" "+TRIM(cLast) ENDIF RETURN cFullName |
See Also |