Call 陳述式 (Visual Basic)Call Statement (Visual Basic)

將控制權轉移至 FunctionSub或動態連結程式庫(DLL)程式。Transfers control to a Function, Sub, or dynamic-link library (DLL) procedure.

語法Syntax

[ 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. 如果您包含 argumentList,就必須將它括在括弧中。If you include argumentList, you must enclose it in parentheses.

備註Remarks

當您呼叫程式時,可以使用 Call 關鍵字。You can use the Call keyword when you call a procedure. 對於大部分的程序呼叫,您不需要使用此關鍵字。For most procedure calls, you aren’t required to use this keyword.

當被呼叫的運算式不是以識別碼開頭時,您通常會使用 Call 關鍵字。You typically use the Call keyword when the called expression doesn’t start with an identifier. 不建議針對其他用途使用 Call 關鍵字。Use of the Call keyword for other uses isn't recommended.

如果程式傳回值,Call 語句會將它捨棄。If the procedure returns a value, the Call statement discards it.

範例Example

下列程式碼顯示兩個範例,其中需要 Call 關鍵字來呼叫程式。The following code shows two examples where the Call keyword is necessary to call a procedure. 在這兩個範例中,被呼叫的運算式不是以識別碼開頭。In both examples, the called expression doesn't start with an identifier.

Sub TestCall()
    Call (Sub() Console.Write("Hello"))()

    Call New TheClass().ShowText()
End Sub

Class TheClass
    Public Sub ShowText()
        Console.Write(" World")
    End Sub
End Class

請參閱See also