Parameters & Return Types¶
Functions and subs in CrossBasic can accept zero or more parameters and (for functions) return a value.
Parameter List¶
Parameters are declared in the parentheses following the routine name:
- Each parameter has a name, an As type, and may be Optional with a default value.
- Types can be built-in (e.g.
Integer,Double,String,Boolean) or user-defined classes. - Parameters are evaluated left-to-right. Optional parameters must come after all required ones.
Example¶
Function ComputeArea(width As Double, height As Double) As Double
Return width * height
End Function
This ComputeArea function takes two Double parameters and returns their product.
Return Types¶
- Only Functions specify a return type with
As ReturnType. - Subroutines do not specify a return type.
Accepted return types include all built-in types and any Class or Enum.
Example¶
Special “Assigns” Parameters¶
Using the Assigns keyword transforms the final parameter into an l-value: