Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
Interaction Class
 CallByName Method

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework Class Library
Interaction..::.CallByName Method

Executes a method on an object, or sets or returns a property on an object.

Namespace:  Microsoft.VisualBasic
Assembly:  Microsoft.VisualBasic (in Microsoft.VisualBasic.dll)
Visual Basic (Declaration)
Public Shared Function CallByName ( _
    ObjectRef As Object, _
    ProcName As String, _
    UseCallType As CallType, _
    ParamArray Args As Object() _
) As Object
Visual Basic (Usage)
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)
C#
public static Object CallByName(
    Object ObjectRef,
    string ProcName,
    CallType UseCallType,
    params Object[] Args
)
Visual C++
public:
static Object^ CallByName(
    Object^ ObjectRef, 
    String^ ProcName, 
    CallType UseCallType, 
    ... array<Object^>^ Args
)
JScript
public static function CallByName(
    ObjectRef : Object, 
    ProcName : String, 
    UseCallType : CallType, 
    ... Args : Object[]
) : Object

Parameters

ObjectRef
Type: System..::.Object
Required. Object. A pointer to the object exposing the property or method.
ProcName
Type: System..::.String
Required. String. A string expression containing the name of the property or method on the object.
UseCallType
Type: Microsoft.VisualBasic..::.CallType
Required. An enumeration member of type CallType Enumeration representing the type of procedure being called. The value of CallType can be Method, Get, or Set.
Args
Type: array<System..::.Object>[]()[]
Optional. ParamArray. A parameter array containing the arguments to be passed to the property or method being called.

Return Value

Type: System..::.Object
Executes a method on an object, or sets or returns a property on an object.

For more detailed information, see the Visual Basic topic CallByName Function.

The CallByName function is used at runtime to get a property, set a property, or invoke a method.

In the following example, the first line uses CallByName to set the Text property of a text box, the second line retrieves the value of the Text property, and the third line invokes the Move method to move the text box.

Visual Basic
' Imports statements must be at the top of a module.
Imports Microsoft.VisualBasic.CallType

Visual Basic
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

The next example uses the CallByName function to invoke the Add and Item methods of a collection object.

Visual Basic
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 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker