Each object in the collection can also be referred to by its specific ordinal
number. This is an item number automatically assigned as the new items are added
to the collection.
When referring to the ordinal number of a form,
you must always remember that the Forms Collection
is 0-based. The first item in the collection
will always have the ordinal value of 0. The
following lines demonstrate using the item value:
Forms(0).Caption
Forms(1).Name
Forms(2).Width
This code assumes that a VB project has three
forms and that all forms have been loaded into
memory. The first line will return the Caption
of the very first item (item 0) in the collection.
The second line will return the Name property
of Form(1). The third line will return the value
of the last form's width.
These code examples show how easy referencing specific items in the collection
can be. This can be an alternative method to using the specific form names in
a given project. With the Forms Collection,
you also do not have to know the name of a given form to control it. This will
assist in manipulating forms generated at runtime.
Using the forms collection topics
See Also