Can anyone explain how to use collections (i.e. control collections). Please give examples.
Printable View
Can anyone explain how to use collections (i.e. control collections). Please give examples.
Try this. The following example requires a Form with 2 CommandButtons and a ListBox
Code:Dim X As Collection
Private Sub Command1_Click()
'Add an item to the collection
X.Add InputBox("Enter a name")
End Sub
Private Sub Command2_Click()
'Display all the items in the collection
For I = 1 To X.Count
List1.AddItem X(I)
Next I
End Sub
Private Sub Form_Load()
'Create the collection
Set X = New Collection
End Sub