Sub aa(byref NewLable as Lable) NewLable.Caption="sub aa()" End Sub
例如:窗体上放一个LABEL1控件.Option ExplicitPrivate Sub Command1_Click() myfun "Label1" End SubSub myfun(ctrname As String) CallByName Form1, ctrname, VbLet, "asd" End Sub
Option ExplicitPublic WithEvents Ev_Label As VB.LabelPrivate Sub Command1_Click() MyFun "Label1" End SubSub MyFun(CtrName As String) Dim Ctr As Control For Each Ctr In Me.Controls If UCase$(Ctr.Name) = UCase$(CtrName) Then Set Ev_Label = Ctr Exit For End If Next End SubPrivate Sub Ev_Label_Click() MsgBox Ev_Label.Name End Sub
Private Sub Form_Click() aa Label1 aa Text1 aa Command1 End SubPrivate Sub aa(bb As Object) bb.Left = 500 End Sub
引用 Microsoft Script ConTrol 1.0如:Dim SCR As New ScriptControl SCR.Language = "vbscript"
NewLable.Caption="sub aa()"
End Sub
myfun "Label1"
End SubSub myfun(ctrname As String)
CallByName Form1, ctrname, VbLet, "asd"
End Sub
Option ExplicitPublic WithEvents Ev_Label As VB.LabelPrivate Sub Command1_Click()
MyFun "Label1"
End SubSub MyFun(CtrName As String)
Dim Ctr As Control
For Each Ctr In Me.Controls
If UCase$(Ctr.Name) = UCase$(CtrName) Then
Set Ev_Label = Ctr
Exit For
End If
Next
End SubPrivate Sub Ev_Label_Click()
MsgBox Ev_Label.Name
End Sub
aa Label1
aa Text1
aa Command1
End SubPrivate Sub aa(bb As Object)
bb.Left = 500
End Sub
SCR.Language = "vbscript"
SCR.AddObject "DG", JPFrm.DG1, True
SCR.AddObject "Colorcom", ColorCom, True
SCR.AddCode "ColorCom.BackColor = DG." & TV1.SelectedItem.Key
Set SCR = Nothing