Sub Statement
[ClassBehavior
] [AccessModifier
] Subname
[(arglist
)] [statements
] [Exit Sub] [statements
] End Sub
ClassBehavior
optional; KeywordOne of the keywords shown in the following table:
Keyword |
Description |
|
Indicates that more than one declaration of this subroutine exists (with different argument signatures). |
|
For derived classes, indicates that the subroutine overrides the subroutine by the same name (and argument signature) in the base class. |
|
Indicates that the subroutine can be overridden in a derived class. |
|
Indicates that the subroutine cannot be overridden in a derived class. |
|
Indicates that the subroutine must be overridden in a derived class. |
|
In a derived class definition, indicates that calls to derived class members that are made through a base class ignore the shadowed implementation. |
|
Callable without creating an object of the class. It is, in this strange sense, shared by all objects of the class. These are also called static subroutines. |
AccessModifier
optionalPossible values are Public
,
Private
, Friend
,
Protected
, or Protected
Friend
. The following table describes the effects
of the various access modifiers. Note that “direct
access” refers to accessing the member without any
qualification, as in:
classvariable = 100
and “class/object access” refers to accessing the member through qualification, either with the class name or the name of an object of that class.
Direct access scope |
Class/objectaccess scope | |
|
Declaring class |
Declaring class |
|
All derived classes |
Declaring class |
|
Derived in-project classes |
Declaring project |
|
All derived classes |
Declaring project |
|
All derived classes |
All projects |
name
required; String literalThe name of the Sub procedure.
arglist
optional; anyA comma-delimited list of variables to be passed to the sub procedure as arguments from the calling procedure.
arglist
uses the following syntax and
parts:
[Optional] [ByVal | ByRef] [ParamArray]varname
[( )] _ [Astype
] [=defaultvalue
]
Optional
optional; KeywordAn optional argument is one that need not be supplied when calling
the function. However, all arguments following an optional one must
also be optional. A ParamArray
argument cannot be
optional.
ByVal
optional; KeywordThe argument is passed by value; that is, the local copy of the
variable is assigned the value of the argument.
ByVal
is the default method of passing variables.
ByRef
optional; KeywordThe argument is passed by reference; that is, the local variable is simply a reference to the argument being passed. All changes made to the local variable will be reflected in the calling argument.
ParamArray
optional; KeywordIndicates
that the argument is an optional array containing an arbitrary number
of elements. It can only be used as the last element of the argument
list, and cannot be modified by either the ByRef
or Optional
keywords. If Option
Strict
is on, the array type must also be specified.
varname
required; String literalThe name of the local variable containing either the reference or value of the argument.
type
optional; KeywordThe data type of the argument. It can be Boolean, Byte, Char, Date, Decimal, Double, Integer, Long, Object, Short, Single, String, a user- defined type, or an object type.
defaultvalue
optional; anyFor optional arguments, you must specify a default value.
statements
optionalProgram code to be executed within the procedure.