Call Statement

Description

Transfers control to a Sub procedure, Function procedure, dynamic-link library (DLL) procedure, or a Macintosh® code resource procedure.

Syntax

[Call] name [argumentlist]

The Call statement syntax has these parts:

Part Description
Call Optional keyword; if specified, you must enclose argumentlist in parentheses. For example:
Call MyProc(0)
name Name of the procedure to call.
argumentlist Comma-delimited list of variables, arrays, or expressions to pass to the procedure. Components of argumentlist may include the keywords ByVal or ByRef to describe how the arguments are to be treated by the called procedure. However, ByVal and ByRef can be used with Call only when making a call to a DLL procedure or a Macintosh code resource.


Remarks

You are not required to use the Call keyword when calling a procedure. However, if you use the Call keyword to call a procedure that requires arguments, argumentlist must be enclosed in parentheses. If you omit the Call keyword, you also must omit the parentheses around argumentlist. If you use either Call syntax to call any intrinsic or user-defined function, the function’s return value is discarded.

To pass a whole array to a procedure, use the array name followed by empty parentheses.

See Also

Declare Statement.

Example

This example illustrates how the Call statement is used to transfer control to a Sub procedure, an intrinsic function, a dynamic-link library (DLL) procedure, and a procedure in a Macintosh code resource.


' Call a Sub procedure.PrintToDebugWindow("Hello World")    
' The above statement causes control to be passed to the following
' Sub procedure.PrintToDebugWindow(AnyString)
    Debug.Print AnyString            ' Print to Debug window.Sub
' Call an intrinsic function. The return value of the function is
' discarded.Shell(AppName, 1)                ' AppName contains the path of the 
                                    ' executable file.
' Call a Microsoft Windows DLL procedure. The Declare statement must be 
' Private in a Class Module, but not in a standard Module.Declare Sub MessageBeep Lib "User" (ByVal N As Integer)CallMyDll()
    Call MessageBeep(0)                ' Call Windows DLL procedure.
    MessageBeep 0                    ' Call again without Call keyword.Sub
' Call a Macintosh code resource.Sub MessageAlert Lib "MyHd:MyAlert" Alias "MyAlert" (ByVal N _
    As Integer)CallMyCodeResource()
    Call MessageAlert(0)                ' Call Macintosh code resource.
    MessageAlert 0                    ' Call again without Call keyword.Sub