Communicating with Procedures Using Arguments

If you need to supply a procedure with information so that it can perform its task, you pass that information in the form of arguments. When you declare an argument, you can specify the data type of the argument, whether or not the procedure can change the argument's value, and whether an argument is required or optional. For more information, see the following sections.

To indicate that a given procedure takes arguments, include an argument list between the parentheses that follow the procedure name in the procedure declaration. The argument list can contain multiple argument declarations, separated by commas.

The following example shows the declaration line of a Sub procedure that takes two arguments.


Sub UpdateRecord(custId, custName)

The following code calls UpdateRecord.


Dim newId As Integer
Dim newName As String

newId = 3452
newName = "Mary Boyd"
UpdateRecord newId, newName

Note that the name of the variable you pass from the calling procedure doesn't have to match the name of the argument declared in the called procedure.

If you pass an array as an argument, you must include empty parentheses after the array name. Because you don't specify the dimensions of the array, the procedure can accept arrays of any size. The following example shows a declaration line for a Sub procedure that takes an array as an argument.


Sub PrintList(custArray())

Arguments have the same scope as variables declared within a procedure — that is, local (procedure-level) scope. They're not accessible outside the procedure in whose argument list they're declared.