Returning from a subroutine or function¶
return |
Return from a subroutine or function |
SYNTAX
return [expression | object_id]
Returns program control from a subroutine or function.
Subroutines |
Control is passed to the statement following the calling gosub command. Subroutines may not return a value. |
User functions |
Control passes to the statement following the function call. [expression | object_id] A function may return a value, which may be a constant, an expression involving constants, operators and field names, or the name of an object within the program. If a function returns without specifying a return value, the null object is returned. This equates to 0 if assigned to a field. If the return value is a global object, the object_id is returned and the return value may be used where an object_id is valid. If the return value is a local object (!temp), its value is returned, since the object will not exist once the function has returned. User functions are declared by !function. |
Validation functions |
The return statement is used to return status from a validation function (event code EV_VALIDATE), indicating whether the data entered into a textbox or table cell was valid or invalid. Returning a value of 0, or OKAY, or a plain return statement with no value, indicates that the data was valid; other return statuses exist with a variety of different meanings. See Textboxes; Textbox validation function; Tables; Table events and event functions; dialog. |
NOTES
All pending return statements are maintained on an internal stack. A Stack overflow error occurs if subroutines are nested more than 90 levels deep.
An end command clears the internal stack and thus clears any pending return statements
EXAMPLES
Function. This function strips a suffix of up to 3 characters from a string:
!function RemoveSuffix(OldString) {
!temp NewString,,a255
!temp DotPos,,i2
DotPos = instr(OldString, strlen(OldString) -3, ".")
switch (DotPos) {
case = 0:
NewString = OldString
break
default:
NewString = getstr(OldString, 1, DotPos -1)
}
return NewString
}
Subroutine:
gosub DISPLAY
...
DISPLAY:
display st.name, st.add1
for (setrow 1; sys.Row <= 10; setrow +1) {
display st.cat, st.code
}
return
RELATED TOPICS |