Interaction.CallByName(Object, String, CallType, Object[]) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
對物件執行方法,或設定或回傳物件屬性。
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。 一個包含物件屬性或方法名稱的字串表達式。
- Args
- Object[]
Optional.
ParamArray。 一個參數陣列,包含要傳遞給被呼叫屬性或方法的參數。
傳回
對物件執行方法,或設定或回傳物件屬性。
例外狀況
無效 UseCallType 值;必須是 Method、 Get、 或 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 函式在執行時用來取得屬性、設定屬性或呼叫方法。