怎样根据对象名称把对象赋值给一个Object类型的变量?
像这样:dimaasobjectsubloadobject(nameasstring)a=***name****'根据name来设置aendsub怎样弄上面那个过程?比如...
像这样:
dim a as object
sub loadobject(name as string)
a=***name**** '根据name来设置a
end sub
怎样弄上面那个过程?
比如输入name是"label1",a就赋为Label1
怎么弄???? 展开
dim a as object
sub loadobject(name as string)
a=***name**** '根据name来设置a
end sub
怎样弄上面那个过程?
比如输入name是"label1",a就赋为Label1
怎么弄???? 展开
2个回答
展开全部
Sub LoadObject(name As String)
Dim a As Object
Set a = Controls.Add("vb.label", name) '前一个参数必须定义object类型,比如vb.commandbutton、vb.textbox等
a.Caption = Rnd '此条为显示时的标志符,创建textbox时,设置a.text=rnd
a.Visible = True '此条是必须的,否则创建的控件不可见
End Sub
Private Sub Command1_Click()
Call LoadObject("label1")
Controls("label1").Top = 0 '如何引用,创建了什么控件,就以什么控件的属性列表设置它
End Sub
Private Sub Command2_Click()
Call LoadObject("label2")
Controls("label2").Top = Command2.Top
End Sub
Dim a As Object
Set a = Controls.Add("vb.label", name) '前一个参数必须定义object类型,比如vb.commandbutton、vb.textbox等
a.Caption = Rnd '此条为显示时的标志符,创建textbox时,设置a.text=rnd
a.Visible = True '此条是必须的,否则创建的控件不可见
End Sub
Private Sub Command1_Click()
Call LoadObject("label1")
Controls("label1").Top = 0 '如何引用,创建了什么控件,就以什么控件的属性列表设置它
End Sub
Private Sub Command2_Click()
Call LoadObject("label2")
Controls("label2").Top = Command2.Top
End Sub
展开全部
Sub LoadObject(objName As String, sCaption As String)
Dim obj As Object
Set obj = Me.Controls(objName)
obj.Caption = sCaption
End Sub
Private Sub Command1_Click()
Call LoadObject("label1", "这样就可以了")
End Sub
Dim obj As Object
Set obj = Me.Controls(objName)
obj.Caption = sCaption
End Sub
Private Sub Command1_Click()
Call LoadObject("label1", "这样就可以了")
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询