Declaring Functions & Subroutines¶
CrossBasic supports two kinds of callable routines:
- Function: Returns a value.
- Subroutine (or Sub): Does not return a value.
Syntax¶
Function FunctionName(parameterList) As ReturnType
' …body…
End Function
Sub SubName(parameterList)
' …body…
End Sub
- The
Functionkeyword introduces a routine that must end withEnd Functionand specify anAsreturn type. - The
Subkeyword introduces a routine that must end withEnd Suband does not have a return type. - Both names are case-insensitive and follow the same naming rules as variables (letters, digits, underscores; must not start with a digit).
Examples¶
Simple Function¶
This defines a function Bar that takes no parameters and returns the integer 1.
Subroutine¶
This defines a subroutine PrintGreeting that prints a message and returns no value.
Assigns-style “Function” for L-value syntax¶
CrossBasic additionally supports the Assigns keyword to make functions act like l-values: