Beruflich Dokumente
Kultur Dokumente
Then, you use the Add method to add items to the collection:
You wouldn't use the before and after arguments at the same time. If you omit both
arguments, the new item is placed at the end of the collection. If you use one of these
arguments, it must refer to an existing member of the collection or else an error will occur.
col.Item(index)
The index argument is either a number specifying the position of the item in the collection,
or the key string that was specified when the item was added. If the index argument doesn't
match an item in the collection, an error occurs. Note that the numerical index is one-based;
in other words, it runs from 1 to the number of items in the collection. Since Item is the
default method, you can use the shorthand syntax like this:
col(index)
To delete an item, use the Remove method. Its syntax is exactly the same as Item. If you
remove an item that isn't the last item, other items move up to fill in the space of the deleted
item.
The Collection object has one property, Count. It returns the number of items in the
collection.
Collections can be useful in various situations. For instance, suppose your program lets the
user create one or more child windows. You can use a collection to keep track of them and
then destroy them as needed. First, create the collection:
When it's time to close all the windows, loop through the collection, like this:
Dim i As Integer
Dim f As Form
For i = 1 To col.Count
Set f = col(i)
f.Visible = False
Set f = Nothing
Next