Parameters and Arguments
Consider the following very simple subroutine, which does nothing more than display a message box declaring a person’s name:
Sub DisplayName(sName As String) MsgBox "My name is " & sName End Sub
To call this subroutine, we would write, for example:
DisplayName "Wolfgang"
or:
Call DisplayName("Wolfgang")
The variable sName
in the procedure
declaration:
Sub DisplayName(sName As String)
is called a
parameter
of the
procedure. The call to the procedure should contain a string variable
or a literal string that is represented by the variable
sName
in this procedure. (but see the
discussion of optional arguments in the next section). The value used
in place of the parameter when we make the procedure call is called
an
argument
. Thus, in
the previous example, the argument is the string
“Wolfgang.”
Note that many programmers incorrectly fail to make a distinction between parameters and arguments, using the names interchangeably. However, since a parameter is like a variable and an argument is like a value of that variable, failing to make this distinction is like failing to distinguish between a variable and its value!
Optional Arguments
In VBA, the arguments to a procedure may be specified as
optional,
using the Optional
keyword. (It makes no sense to
say that a parameter is optional; it is the
value that is optional.)
For instance, the definition of the OpenRecordset method is:
Setrecordset
=object
.OpenRecordset(source
,type
,options
,lockedits
)
where type
, options
, and ...
Get Access Database Design and Programming, Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.