RETURN
expr | = alpha, numeric or OBJECT expression |
The RETURN statement is used to mark the end of a subroutine and to return program flow to the statement immediately following the most recent GOSUB or GOSUB' statement. RETURN can also be used to return alphanumeric values if the routine was called from within an alphanumeric expression (See GOSUB'). The RETURN statement also terminates any open FOR ... NEXT loops within the subroutine, and removes their entries from the RETURN stack. Any non-unique locally defined variables defined with either the DEFSUB' or LOCAL DIM are also removed.
If RETURN is used to return a value back to an expression, the type of value returned must match the type of subroutine. E.g.
search$ = 'Next_rec$(stream)
Total = 'Calculate(bal())
.
.
.
DEFSUB 'Next_rec$()
.
.
.
RETURN Record$
DEFSUB 'Calculate(array())
.
.
.
RETURN total_of_balances
If a subroutine contains a FINALLY clause then the code in that clause between the FINALLY keyword and the mandatory END SUB will be executed after the RETURN. Note that there can only be one FINALLY clause in a subroutine and it may not contain any further RETURN statements. FINALLY is only allowed if $COMPLIANCE is 1 or more and therefore all DEFSUBs have matching END SUBs.
If a RETURN statement is encountered in a routine called by a function key, RETURN returns control to immediate mode if the function key was pressed in immediate mode, or control is returned to the interrupted LINPUT statement. If a LINPUT statement is interrupted, RETURN returns control to the statement following the LINPUT statement.
RETURN was once used as a keyword prefixing arguments in $DECLARE calls and object method calls. This use is now deprecated and BYREF should be used instead.
'KCMLCORBACreate("myObject","Add",RETURN myhandle)
worksheet.Range("A9").Value(RETURN t)
worksheet.Range("A9").Value(RETURN NUM(t))
worksheet.Range("A10:D11").Value(BYREF t())
Compatibility
FINALLY was introduced with KCML 6.60. BYREF replaced RETURN in $DECLARE and method calls in KCML 5.02.
See also: