Actual and formal parameters

I had a few questions about this in class today, so I think it’s worth going back over it.

Parameters are used by procedures and functions to pass information in and out. They are used in the definition and in the call of these constructs.

  • The parameters used in the procedure/function definition are called the formal parameters.
  • The parameters used in the procedure/function call are called the actual parameters.

Take a look at the dice roll program

You can see the line Private Sub Dicethrow(ByRef diceside As Integer) which is the definition, diceside is the formal parameter. However, the call Call Dicethrow(DiceRolls(Roll)) has the actual parameter as DiceRolls(Roll). In this case we are passing the value from the array into the integer variable.

In the case of the line Private Sub DisplayRolls(ByVal Rolls() As Integer) the formal parameter is Rolls(). While the call DisplayRolls(DiceRolls) uses the array DiceRolls as the actual parameter.

So why are there two different types of parameter?

This allows modules (procedures) to be used in libraries without the programmer having to use the formal parameter names. Visual basic also helps once the procedure/function is created by displaying the formal parameters automatically as you type in the call. What do you think that means from the example below?