A procedure or a function may need an external value in order
to perform its action. A value that is supplied to a procedure is called
a parameter.

When creating a procedure or function that will use an external
value, in the parentheses of the procedure or function, write the name of the parameter followed by As and the data type of the parameter. Based on this, the formula to follow for a procedure is:

As mentioned previously, you can also use the Call
keyword to call a procedure.

A Function or Procedure With Many Parameters

Introduction

A function or a procedure can use more than one parameter. In this case, the parameters are separated by commas. In the body the procedure or functionm, you can ignore all parameters, you can decide to use only one or some of them, or you can use all parameters. Here is an example:

When you call a procedure that takes more than one
argument, you must provide the values of the arguments in the exact order
they are listed inside of the parentheses of the function. Here are examples:

When calling a procedure or a function, instead of providing the arguments in the exact order the parameters appear, you can access each parameter by its name and assign the desired value. To do this, in the parentheses of the procedure or function, type the name of parameter, followed by the := operator, followed by the desired value for the argument. You can list the combinations in any order of your choice and the assignments must be separated by commas. Here are examples:

When calling a procedure or function that
takes an argument, the procedure or function makes a copy of the value of the
argument and makes that copy available to the calling procedure or function. The parameter itself is not accessed. This is referred to as passing an
argument by value. To indicate this concept, type the ByVal
keyword on the left side of the argument. Here are examples:

When passing an argument to a function, instead of passing the value of the argument, you can first declare a variable that would hold the value but instead pass the address of the variable. This technique is referred to as passing an argument by reference. When this is
done, any action performed on the argument will be kept. For example, if the value of the argument is modified, the argument would now
have the new value, dismissing or losing the original value it had.

To pass an argument by reference, in the parentheses of the procedure or function, instead of applying ByVal to the parameter, type
the ByRef keyword. When calling the procedure or function, you must pass the name of an initialized variable for the parameter. Here is an example:

Using this technique, you can pass as many arguments
by reference and as many arguments by value as you want. As you may guess
already, this technique can be used to make a procedure return one or more values,
which a regular procedure cannot do. Furthermore, passing arguments by
reference allows a function or a procedure to return as many values as possible while a
regular function can return only one value.

Other Techniques of Passing Arguments

Optional Arguments

If you create a procedure or a function that takes one or more
arguments, whenever you call that procedure, you must provide a value for
each parameter. If a certain argument is passed with the same value almost ever time, you can provide a default value to the parameter. Its argument becomes referred to as optional.

To specify that an argument is
optional, when creating its procedure or function, in the parentheses, type the Optional keyword to
the left of the ByVal qualifier of the parameter and assign the desired default value to it. Here is
an example:

If a function or a procedure takes more than one argument, you can
provide a default argument for each and select which ones would have
default values. If you want all arguments to have default values, when
defining the procedure or function, provide the Optional keyword for each parameter and
assign the desired default value to it. Here is an example:

If you are creating a procedure or a function that has more than one parameter and a (some) parameter(s) must be optional, the parameter(s) that has(have) (a) default value(s)
must be the last in the procedure. This means that:

If a procedure or a function has two parameters and one parameter has a default
value, this optional parameter must be the second in the list of parameters

If a procedure or function is taking three or more parameters and two or more
parameters have default values, these optional parameters must by placed
to the right of the non-optional parameter(s).

Because of this, when calling any procedure in the
Visual Basic language, you must know what, if any, parameter is optional
and which one is not.

If a procedure takes two arguments and one argument
has a default value, when calling this procedure, you can pass only one
value. In this case, the passed value would be applied on the first
argument. If a procedure takes more than two arguments and two or more
arguments have a default value, when calling this procedure, you can
provide only the value(s) of the argument(s) that is (are) not optional. A better alternative is to access the parameters by name to identify only the parameters that need values. Here is an example:

You can create many procedures or functions that have the same name in the same scope. The ability to have various procedures with the same
name is referred to as overloading. When creating the procedures or functions, each one of them must have a different number of, and (a) different type(s) of, parameters. When calling a version of the procedures, make sure you pass the appropriate type(s) or (number) of argument(s) to indicate the one you want. Here is an example:

We already know that a variable is constant if its
value never changes. Such a variable can be declared in a code delimiter
or in a procedure/function. A read-only variable is a constant type that
be declared only as a global variable. It is created using the ReadOnly keyword.

As done for a constant, when declaring a ReadOnly
variable, you should initialize it. If you don't, it would
receive a default value based on its type. For example, a number-based
variable would be initialized with 0 and a String variable would be
initialized with an empty string.

A variable declared locally in a procedure belongs to it and its influence
doesn't expand beyond the body of the procedure. If you want a locally
declared variable to keep its changed value when its host procedure is
exited, declare such a variable as static.

Declaring a Static Variable

To declare a static variable, type the Static
keyword on the left of the Dim keyword. You should always
initialize a static variable before using it. Here are examples: