CitectVBA Programming Reference > Understanding CitectVBA Language Basics > Subroutines and Functions > Subroutines

Subroutines

A CitectVBA subroutine starts with the SUB statement and finishes with the END SUB statement. All other statements that lie between the SUB and END SUB statements, will be executed by the subroutine, when called to do so.

Note: In the following subroutine syntax example:

In CitectVBA, Subroutines are created with the SUB statement in the following format.

Sub <SubName> ( [ Byval ] [ <Argument/s> ] [ <As Data Type> ])
<statement>
<statement>
<statement>
End Sub

where:

The name given to the subroutine immediately follows the SUB keyword, and is used to identify the subroutine to CitectVBA. This name is referred to when the subroutine is called upon (called) to be executed (perform the statements it contains) by some other procedure in CitectVBA.

Subroutine names can contain the letters 'A' to 'Z' and 'a' to 'z', the underscore '_' and digits '0' to '9'. The subroutine name must begin with a letter, be no longer than 40 characters, cannot contain the space character, and cannot be a reserved word. Subroutine names (once declared), become a keyword in CitectVBA. Like most keywords in CitectVBA, these names are not case sensitive.

The subroutine name always ends with a pair of parentheses ( ) which may or may not contain one or more arguments required by (necessary for use in) the subroutine . Multiple arguments if used, are separated by commas ( , ). See Arguments for more details and argument syntax.

All the lines located between the SUB and the END SUB statements, contain the statements that will be executed when the subroutine is called in CitectVBA. These statements will be executed one at a time in logical order from top to bottom within the subroutine.

See Also

Subroutines and Functions

Functions

Arguments