Export (0) Print
Expand All
Expand Minimize

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.

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.

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 Basic
For Each f As Form In My.Application.OpenForms
    f.Text = "Hello"
Next


Community Additions

ADD
Show:
© 2014 Microsoft