Sub name [ (parameterlist) ]
   [ statements ]
   [ Return [value]]
   [ statements ]
End Sub


Declares the name, parameters, and code that define a Sub procedure or function.


The Sub name must begin with a letter (a..z or A..Z) and can be followed by letters, digits, or the "_" character.


The parameter list contains one or more variables separated by commas. The data type must not be declared. Parameters passed by reference must be declared using the ByRef directive.


You can use the Return statement to exit a Sub. To return a value, use Return <value>, for example Return $result.


Example:

Sub TotalPixels($width, $height, ByRef $total)

   ' -1 indicates an error
   $total = -1

   ' exit immediately if width or height is zero
   If ($width = 0) Or ($height = 0) Then
      Return
   End If

   $total = $width * $height
End Sub

'*******************************************

Sub Max($a, $b)
   If $a > $b Then
      Return $a
   Else
      Return $b
   End If
End Sub