Public Function CallByName( _ ByVal ObjectRef As System.Object, _ ByVal ProcName As String, _ ByVal UseCallType As CallType, _ ByVal Args() As Object _) As Object
示例
在下面的示例中,第一行使用 CallByName 设置文本框的 Text 属性,第二行检索 Text 属性的值,第三行调用 Move 方法以移动文本框。
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
下一个示例使用 CallByName 函数调用集合对象的 Add 和 Item 方法。
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