Interaction.CallByName(Object, String, CallType, Object[]) Method

Definition

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

C#
public static object? CallByName(object? ObjectRef, string ProcName, Microsoft.VisualBasic.CallType UseCallType, params object?[] Args);
C#
public static object CallByName(object ObjectRef, string ProcName, Microsoft.VisualBasic.CallType UseCallType, params object[] Args);

Parameters

ObjectRef
Object

Required. Object. A pointer to the object exposing the property or method.

ProcName
String

Required. String. A string expression containing the name of the property or method on the object.

UseCallType
CallType

Required. An enumeration member of type CallType representing the type of procedure being called. The value of CallType can be Method, Get, or Set.

Args
Object[]

Optional. ParamArray. A parameter array containing the arguments to be passed to the property or method being called.

Returns

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

Exceptions

Invalid UseCallType value; must be Method, Get, or Set.

Examples

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.

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

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

VB
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

Remarks

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

Applies to

Product Versions
.NET Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1

See also