CallByName 函数
执行对象的方法,或者设置或返回对象的属性。
语 法:
CallByName (object, procname, calltype, [args () ]_)
CallByName 函数语法具有以下 命名参数:
Part
|
说明
|
object
|
必需: Variant (Object) 。 将对其执行函数的对象的名称。
|
procname
|
必需: Variant (String) 。 包含对象的属性或方法的名称的字符串表达式。
|
calltype
|
必需: 常量。 一个类型为 vbCallType 的常量,它表示要调用的过程的类型。
|
args ()
|
可选:Variant (Array)。
|
备 注:
CallByName 函数用于获取或设置属性,或运行时使用字符串名称调用方法。
在下面的示例中,第一行使用 CallByName 设置文本框的 MousePointer 属性,第二行获取 MousePointer 属性的值,第三行调用 Move 方法移动文本框。
附 件:
点击下载此附件
CallByName
Text1, "MousePointer", vbLet,
vbCrosshair
Result =
CallByName (Text1, "MousePointer", vbGet)
CallByName
Text1, "Move",
vbMethod, 100, 100
示 例:
此示例使用 CallByName 函数调用 Command 按钮的 Move 方法。
该示例还使用一个窗体 (Form1) 一个按钮 Command1 () ,以及一个 Label1 () 。 加载表单时,标签 的 Caption 属性设置为"Move",并设置为要调用的方法的名称。 在单击按钮时, CallByName 函数将调用方法以更改按钮的位置。
Option Explicit
Private Sub
Form_Load()
Label1.Caption = "Move" ' Name of Move method.
End Sub
Private Sub
Command1_Click()
If Command1.Left <> 0 Then
CallByName Command1, Label1.Caption,
vbMethod, 0, 0
Else
CallByName Command1, Label1.Caption,
vbMethod, 500, 500
End If
End sub