Sub Statement

Top  Previous  Next

 

Function:

Used to define subs -- distinct units in code which perform specific tasks. These never return any value.

Syntax:

 

[ public ]

sub name [ ( [ byref ] argument1 as type1, [ byref ] argument2 as type2…) ]

       statement1

       statement2

       …        

       [exit sub]

       …        

       statementN        

end sub

Scope:

Global

See Also:

Declare Statement, Exit Statement, Function Statement

 


Part

Description

public

Optional. If set, allows other compilation units (files in a project) to access the function.

name

Required. Specifies the name for the function (used to call it, etc).

byref

Optional. If present, the argument immediately following this modifier will be passed by reference.

argument[1, 2...]

Optional. The name of the argument(s) passed to the function; arguments must have a name which is a valid identifier. This is a local identifier, used to refer to these arguments within the body of the function.

as

Optional (required if arguments are specified). Precedes the type definition.

type[1, 2...]

Optional (required if arguments are specified). Specifies the data type for the argument. Each argument name must be followed with a type definition, even when specifying several arguments of the same type.

statement[1, 2...]

Required. The body of code executed within the function; specifies the actual 'work' done by the function.

Details

Subroutines cannot be nested (which is why their scope is defined as global or HTML). Subroutines do not return values. Subroutines can call other subroutines and functions.

Examples

 

sub print_to_serial(s as byref string)

       ser.setdata(s)

       ser.send

       s = "OK" ' This sub actually returns something, if indirectly.

end sub