Forms Collection for Visual Basic 6.0 Users

The Visual Basic 6.0 Forms collection is replaced by the My.Application.OpenForms Property property in Visual Basic 2008.

Conceptual Differences

A Visual Basic 6.0 Forms collection is a collection whose elements represented each loaded form in an application. The collection includes the application's MDI form, MDI child forms, and non-MDI forms. The Forms collection has a single property, Count, which specifies the number of elements in the collection.

The Visual Basic 2008 OpenForms property returns a FormCollection object that contains all of the application's open forms. The behavior is the same as the Forms collection, and it can be used in the same ways.

Code Changes for the Forms Collection

The following examples illustrate differences in coding techniques between Visual Basic 6.0 and Visual Basic 2008.

Code Changes for Getting a Count of Open Forms

The following code demonstrates how to return the number of forms currently open in an application.

' Visual Basic 6.0
MsgBox Forms.Count
' Visual Basic
MsgBox(CStr(My.Application.OpenForms.Count))

Code Changes for Setting Properties of All Open Forms

The following code demonstrates how to change the title of each open form in an application.

' Visual Basic 6.0
For Each Form in Forms
    Forms(i).Caption = "Hello"
Next
' Visual BasicForEach f As Form In My.Application.OpenForms
    f.Text = "Hello"Next

See Also

Tasks

How to: Access All Open Forms of an Application

Concepts

Form Object for Visual Basic 6.0 Users

Reference

My.Application.OpenForms Property