Syntax
Marks a FUNCTION parameter that receives the caller variable itself instead of a copy, so that the function can change it.
<name> REF AS <type>
<name> BYREF AS <type>Also written : BYREF
Parts
| <name> | The parameter name. Write it without a sigil. |
|---|---|
| <type> | The parameter type. Required. The value written through the parameter is converted to it. |
Good to know
REFandBYREFare the same word. Both go after the name and beforeAS. The Visual Basic orderBYREF n AS integeris refused ("Invalid BASIC parameter"), and so isREFwithout a type.- The argument must be a place you can assign: a variable, a record field, an array element, the current list element or a map entry. A literal or an expression gives "REF argument is not assignable".
- The type still applies: a
REF AS integerthat receives a float variable writes an integer into it. - A function can pass its own
REFparameter on to anotherREFparameter; the change reaches the first caller. - A
REFparameter cannot beOPTIONALand cannot be variadic. - Do not put a sigil on it.
text$ REF AS stringcompiles, but the program does not run as soon as the body readstext$. Writetext REF AS string. - Without
REF, an untyped parameter already shares a record or an array with the caller; a typed one gets a copy. To keep a link longer than one call, use a handle (@).