变量是指控制数组?

时间:2016-04-22 13:48:54

标签: vb6 controls

我知道它是isn't possible to generate a control array at runtime

但是,是否可以将多个控制数组放在不同的点上,通过变量引用? IE

dim CArray() as controls

CArray = Labels
Foo(CArray)
CArray = OtherLabels
Foo(CArray)

到目前为止,我尝试执行此操作会导致编译时错误,因为它不允许在不使用方法或元素的情况下引用窗体上的实际控件数组。它给出了错误:

  

Arugment不是可选的

1 个答案:

答案 0 :(得分:2)

您可以使用对象:

Private Sub Form_Load()
    Dim CArray As Object
    Set CArray = Labels
    Foo CArray
End Sub

Sub Foo(CtrlArray As Object)
    Dim i as Long
    For i = 0 To CtrlArray.ubound
        CtrlArray(i).Caption = Rnd
    Next
End Sub