Skip to content

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:

Function Name(param1 As Type1, param2 As Type2, Optional param3 As Type3 = default) As ReturnType
  • 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

Function GetMessage() As String
  Return "Welcome!"
End Function

Special “Assigns” Parameters

Using the Assigns keyword transforms the final parameter into an l-value:

Sub ChangeValue(a As Integer, b As Integer, Assigns c As Integer)
  Print("… c = " + Str(c))
End Sub

ChangeValue(2, 3) = 42