天天看點

VB程式設計:将文本控件添加到集合Collection中

程式代碼

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

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

繼續閱讀