自定义的,用callbyname同样适合。 例: callbyname(form1,"a" & i, vbmethod)
callbyname(form1,"a" & i, vbmethod)
中海 CALLBYNAME 正解。当然,你可以将 sub a1() sub a2() sub a3() 合定义为一个过程 sub a(byval index as integer) 如:Sub a1() MsgBox "a1" End Sub Sub a2() MsgBox "a2" End Sub Sub a3() MsgBox "a3" End SubSub a(ByVal index As Integer) If index = 1 Then MsgBox "a1" If index = 2 Then MsgBox "a2" If index = 3 Then MsgBox "a3" End Sub Private Sub Command1_Click() a 3 End Sub
用callbyname(),具体请查阅MSDN的语法说明。
call a2()
call a3()不就行了,何必想好么复杂呢。
object 必需的;变体型(对象)。函数将要执行的对象的名称。
procedurename 必需的;变体型(字符串)。一个包含该对象的属性名称或者方法名称的字符串表达式。
calltype 必需的;常数。一个 vbCallType 类型的常数,代表正在被调用的过程的类型。
arguments() 可选的:变体型(数组)。
说明CallByName 函数用于获取或者设置一个属性,或者在运行时使用一个字符串名称来调用一个方法。在下面的例子中,第一行使用 CallByName 来设置一个文本框的 MousePointer 属性,第二行得到 MousePointer 属性的值,第三行调用 Move 方法来移动文本框:CallByName Text1, "MousePointer", vbLet, vbCrosshair
Result = CallByName (Text1, "MousePointer", vbGet)
CallByName Text1, "Move", vbMethod, 100, 100
好像不能调用函数呵。
sub a2()
sub a3()
for i=1 to 3
call "a"&i()
next
自定义的,用callbyname同样适合。 例: callbyname(form1,"a" & i, vbmethod)
sub a1()
sub a2()
sub a3()
合定义为一个过程
sub a(byval index as integer)
如:Sub a1()
MsgBox "a1"
End Sub
Sub a2()
MsgBox "a2"
End Sub
Sub a3()
MsgBox "a3"
End SubSub a(ByVal index As Integer)
If index = 1 Then MsgBox "a1"
If index = 2 Then MsgBox "a2"
If index = 3 Then MsgBox "a3"
End Sub
Private Sub Command1_Click()
a 3
End Sub