Export (0) Print
Expand All

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 a Visual Basic run-time function (Shell), discard the return value.
Call Shell("C:\WINNT\system32\calc.exe", AppWinStyle.NormalFocus)
' The preceding path is for Windows 2000;
' The Windows XP path C:\Windows\system32\calc.exe.

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

See Also

Declare Statement | Function Statement | Sub Statement

Show:
© 2014 Microsoft