Forms are classes (this says so at the top of each of them):
Public Class MainForm ....
As a class, an instance must be created, however VB allows you to use the default instance using the class name: MainForm.Show()
Under the hood, the compiler creates an instance of MainForm named MainForm and uses it. It is convenient for developers involved in a hobby in the code, but there are many ways that can bite you:
Sub DoSomeThing() Dim frm As New Form1 frm.TextBox1.Text = cp.ToString End Sub
This creates and uses a local instance of Form1 , which is not related to Global Form1 , which was created by VB. The local object goes beyond the scope at the end of the Sub, which will never be used by the rest of the application.
' in sub main: Application.Run(New Form1) ' main form/pump ... elsewhere Form1.TextBox1.Text = "hello, world!"
Despite using the same name, these are actually different instances. The text will not be displayed, and if the next line was Form1.Show() , the second copy of Form1 will be displayed complete with the text "hello, world". They will also create / show new instances:
Form2.Show() ' or Dim frm As New Form2 frm.Show()
In general, the more complex the application, the less suitable is the use of default instances. For serious applications, create explicit instances of the form:
Dim myFrm = New Form7() ' myFrm is an instance of Form7 ... myFrm.TextBox1.Text = vName myFrm.TextBox2.Text = vLastName myFrm.Show
Classes or other forms can be told about this form in various ways, for example, through a property or constructor:
Class Foo Private myFrm As Form7 Public Sub New(frm As Form7) myFrm = frm End Sub ... End Class Dim myFoo = New Foo(Me)
For the main / start form, this can help create a global link:
Module Program Friend frmMain As MainForm End Module
Then set the variable when loading the main form:
Public Class MainForm Private Sub MainForm_Load(sender ...) frmMain = Me End Sub ...
frmMain will be a valid link to the main form for the entire application.