Call Statement (Visual Basic)
Transfers control to a Function, Sub, 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 normally use the Call statement to call a procedure that does not return a value. If the procedure returns a value, the Call statement discards it.
You are not required to use the Call statement when calling a procedure. However, it improves the readability of your code.
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.
' (1) 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)
End Sub
' (2) 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 is C:\Windows\system32\calc.exe.
' (3) 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 callBeepDll()
Call MessageBeep(-1)
End Sub