VB编程:将文本控件添加到集合Collection中-19_彭世瑜_新浪博客

101 阅读1分钟

运行效果

VB编程:将文本控件添加到集合Collection中-19
\

程序代码

Dim aaa As Collection

Private Sub Command1_Click()

    Dim item As Control

    For Each item In aaa

        item.Text = "microsoft"   '对集合中所有TextBox的Text属性赋值

    Next item

End Sub

\

Private Sub Command2_Click()

    Unload Me

End Sub

\

Private Sub Form_Load()

    Set aaa = New Collection

    Dim tex As Control

    For Each tex In Me.Controls

        If TypeName(tex) = "TextBox" Then      '判断是否为TextBox

            aaa.Add tex, tex.Name                       '添加到集合

        End If

    Next tex

End Sub

\