有一个按钮数组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
本示例能debug.print出caption一样,但是控件数组command1的下标跟label控件名中的数值不符合的indexPrivate Sub Form_Click()
Dim ControlS As Control, i As Byte
For Each ControlS In Form1
If LCase(TypeName(ControlS)) = "label" Then
For i = 0 To 5
If Form1.Command1(i).Caption = ControlS.Caption Then
If Replace(ControlS.Name, "Label", "") <> i Then Debug.Print i
End If
Next
End If
Next
End Sub
老师,你这样是列出的控件名相同的index,我想列出名称不相同的index,谢谢
Dim x As Control strSample = Label1 & "|" & Label2 & "|" & Label4
For Each x In Me.Controls
If x.Name = "Command1" And InStr(strSample, x.Caption) < 1 Then
Debug.Print x.Index, x.Caption
End If
Next x