Procedure Calls

Passing Arguments

 

This diagram shows code in 3 separate modules :

 

The two top windows are the ‘click event’ procedures for command buttons
in each of two separate form modules ,“Form1” and “Form2.”

 

Either of these command buttons can be used to “Call” a procedure that is in yet another module,
in this example the module named “Library Code,” that contains program code
for ‘DisplayMessage’ that can be used by any ‘Event Procedure’.

 

The “” procedure needs to know what ‘Message’ to display,
so each “Call” supplies a text string that is “passed” to the “Sub” procedure.

 

In this example, the procedures that call the  procedure,
pass a ‘literal constant’ value, “” in Form1 and “” in Form2.

 

These ‘literal constants’ are transferred (“passed”) to the variable
in the subprogram procedure’s ‘header’ (prototype) line
that defines the parameter variables that are expected to be passed into it.

 

The “Sub” procedure can accept any text string that is “passed” to it,
because its parameter, “,” is defined “.”

 

 

This will display "Hello from Form1" or "Goodbye from Form2,"

depending on which “Current Parent” form was clicked (Form1 or Form2).

 

The “Sub” procedure “prototype” is defined using the “” keyword
so that it can be used by any other procedure in the application.

 

Note that the event procedures that respond to clicking the command buttons
are defined as “” because they respond only to controls in that form module.

 

Note that the procedure  can be in the same module
as the event procedures, or in another, different code module.

ß Back