Avoid Form Confusion

When you define a form named MyForm, Visual Basic creates one instance with the name “MyForm.” Many programmers confuse this special instance with other instances created using Dim. For example, the Caption statement in this code sets the caption on the automatically created instance. When the instance FRM appears, its caption is not set:

 Dim frm As New MyForm	MyForm.Caption = "This is the single instance"	frm.Show

Even more confusing problems can arise if you use MyForm within the MyForm code module, when an instance such as FRM might accidentally set properties on the automatically created form rather than itself. For this reason, never use MyForm within the MyForm code module.

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

Recent Articles: