共用方式為


Interaction.CallByName 方法

在物件上執行方法,或是設定或傳回物件上的屬性。

命名空間: Microsoft.VisualBasic
組件: Microsoft.VisualBasic (在 microsoft.visualbasic.dll 中)

語法

'宣告
Public Shared Function CallByName ( _
    ObjectRef As Object, _
    ProcName As String, _
    UseCallType As CallType, _
    ParamArray Args As Object() _
) As Object
'用途
Dim ObjectRef As Object
Dim ProcName As String
Dim UseCallType As CallType
Dim Args As Object()
Dim returnValue As Object

returnValue = Interaction.CallByName(ObjectRef, ProcName, UseCallType, Args)
public static Object CallByName (
    Object ObjectRef,
    string ProcName,
    CallType UseCallType,
    params Object[] Args
)
public:
static Object^ CallByName (
    Object^ ObjectRef, 
    String^ ProcName, 
    CallType UseCallType, 
    ... array<Object^>^ Args
)
public static Object CallByName (
    Object ObjectRef, 
    String ProcName, 
    CallType UseCallType, 
    Object[] Args
)
public static function CallByName (
    ObjectRef : Object, 
    ProcName : String, 
    UseCallType : CallType, 
    ... Args : Object[]
) : Object

參數

  • ObjectRef
    必要項。Object - 公開屬性或方法之物件的指標。
  • ProcName
    必要項。String。包含物件屬性或方法名稱的字串運算式 (String Expression)。
  • UseCallType
    必要項。型別 CallType 列舉型別 的列舉型別成員,其表示正在呼叫的程序型別。CallType 的值可以是 MethodGetSet
  • Args
    選擇項。ParamArray - 參數陣列,其中包含要傳遞給屬性或正在呼叫的方法之引數。

傳回值

在物件上執行方法,或是設定或傳回物件上的屬性。

備註

如需詳細資訊,請參閱 Visual Basic 的主題 CallByName 函式

CallByName 函式是在執行階段時,用以取得屬性、設定屬性或叫用方法。

範例

在下列範例中,第一行使用 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 函式來叫用集合物件的 AddItem 方法。

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

平台

Windows 98、 Windows 2000 SP4、 Windows CE、 Windows Millennium Edition、 Windows Mobile for Pocket PC、 Windows Mobile for Smartphone、 Windows Server 2003、 Windows XP Media Center Edition、 Windows XP Professional x64 Edition、 Windows XP SP2、 Windows XP Starter Edition

.NET Framework 並不支援各種平台的所有版本。如需支援平台版本的相關資訊,請參閱系統需求一節的內容。

版本資訊

.NET Framework

支援版本:2.0、1.1、1.0

.NET Compact Framework

支援版本:2.0

請參閱

參考

Interaction 類別
Interaction 成員
Microsoft.VisualBasic 命名空間
ArgumentException Class

其他資源

CallByName 函式
CallType 列舉型別
參數陣列
使用字串名稱呼叫屬性或方法