注册 登录
编程论坛 VB6论坛

比较名称找出没有名称的Index

sdhtli 发布于 2012-05-24 14:14, 273 次点击
有一个按钮数组Command1,5个按钮,其Index为不连续的

Command1(1).Caption="qq"  
Command1(2).Caption ="aa"
Command1(4).Caption ="zz"
Command1(5).Caption ="ww"
Command1(7).Caption ="ss"

有数量不固定的Label控件


比如:
Label1.Caption="qq"  
Label2.Caption="aa"  
Label4.Caption="ss"
 
怎么根据Label的Caption比较找出按钮数组Command1中Caption与Label的Caption不相同的Index呢
 For Each pp In Label
  pp.Caption Then
 Next pp

3 回复
#2
wube2012-05-24 15:13
object.item(index)
control("label" & i)
#3
sdhtli2012-05-24 15:27
谢谢,具体代码怎么写呢
#4
wube2012-05-24 19:10
以下是引用sdhtli在2012-5-24 15:27:34的发言:

谢谢,具体代码怎么写呢


(0) + Command1(1) + Command1(3) + ...
程序代码:

Private Sub Form_Load()
Dim MyObject, MyCollection
    Set MyCollection = Me.Controls
    For Each MyObject In MyCollection
        MsgBox MyObject.Index
    Next
End Sub


+ Command2 + Command3 + ...
程序代码:

Private Sub Form_Load()
Dim MyObject, MyCollection
    Set MyCollection = Me.Controls
    For Each MyObject In MyCollection
        MsgBox MyObject.Name
    Next
End Sub


至于找出来做啥就自己加吧...
1