Visual Basic Language Reference  

Call Statement

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

[ Call ] ProcedureName[(ArgumentList)]

Parts

ProcedureName
Required. Name of the procedure to call.
ArgumentList
Optional. List of variables or expressions representing arguments that are passed to the procedure when it is called. Multiple arguments are separated by commas. If you include ArgumentList, you must enclose it in parentheses.

Remarks

You are not required to use the Call keyword when calling a procedure; however, if you use the Call statement to call any intrinsic, DLL, or user-defined function, the function's return value is discarded.

Example

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

' Call a Sub procedure.
Call PrintToDebugWindow("Hello World")   
' The above statement passes control to the following Sub procedure.
Sub PrintToDebugWindow(ByVal AnyString As String)
   Debug.WriteLine(AnyString)   ' Print to the Output window.
End Sub

' Call an intrinsic function. The return value is discarded.
Call Shell("C:\Windows\calc.exe", AppWinStyle.NormalFocus)

' Call a Microsoft Windows DLL procedure. The Declare statement must be 
' Private in a class, not in a module.
Private Declare Sub MessageBeep Lib "User" (ByVal N As Integer)
Sub CallMyDll()
   Call MessageBeep(0)   ' Call Windows DLL procedure.
   MessageBeep(0)   ' Call again without Call keyword.
End Sub

See Also

Declare Statement | Function Statement | Sub Statement