Interaction.CallByName(Object, String, CallType, Object[]) 方法

定義

對物件執行方法,或設定或回傳物件屬性。

public:
 static System::Object ^ CallByName(System::Object ^ ObjectRef, System::String ^ ProcName, Microsoft::VisualBasic::CallType UseCallType, ... cli::array <System::Object ^> ^ Args);
public static object CallByName(object ObjectRef, string ProcName, Microsoft.VisualBasic.CallType UseCallType, params object[] Args);
static member CallByName : obj * string * Microsoft.VisualBasic.CallType * obj[] -> obj
Public Function CallByName (ObjectRef As Object, ProcName As String, UseCallType As CallType, ParamArray Args As Object()) As Object

參數

ObjectRef
Object

必須的。 Object。 指向物件的指標,揭露該屬性或方法。

ProcName
String

必須的。 String。 一個包含物件屬性或方法名稱的字串表達式。

UseCallType
CallType

必須的。 一個型別 CallType 的列舉成員,代表所呼叫的程序類型。 的 CallType 值可以是 MethodGetSet

Args
Object[]

Optional. ParamArray。 一個參數陣列,包含要傳遞給被呼叫屬性或方法的參數。

傳回

對物件執行方法,或設定或回傳物件屬性。

例外狀況

無效 UseCallType 值;必須是 MethodGet、 或 Set

範例

以下範例中,第一行用於 CallByName 設定 Text 文字框的屬性,第二行取得該屬性的 Text 值,第三行則呼叫 Move 移動文字框的方法。

' Imports statements must be at the top of a module.
Imports Microsoft.VisualBasic.CallType
Sub TestCallByName1()
    'Set a property.
    CallByName(TextBox1, "Text", CallType.Set, "New Text")

    'Retrieve the value of a property.
    MsgBox(CallByName(TextBox1, "Text", CallType.Get))

    'Call a method.
    CallByName(TextBox1, "Hide", CallType.Method)
End Sub

下一個範例使用 CallByName 函式來呼叫 Add 集合物件的 and Item 方法。

Public Sub TestCallByName2()
    Dim col As New Collection()

    'Store the string "Item One" in a collection by 
    'calling the Add method.
    CallByName(col, "Add", CallType.Method, "Item One")

    'Retrieve the first entry from the collection using the 
    'Item property and display it using MsgBox().
    MsgBox(CallByName(col, "Item", CallType.Get, 1))
End Sub

備註

這個 CallByName 函式在執行時用來取得屬性、設定屬性或呼叫方法。

適用於

另請參閱