O'Reilly logo

Microsoft® Visual Basic® 2010 Developer’s Handbook by Klaus Löffelmann and Sarika Calla Purohit

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Calling Forms Without Instantiation

In Visual Basic 6.0 and VBA, you had to instantiate an object that you wanted to work with. For example, if you used a Collection to store other objects, you had to create it first by using the following code:

Dim collection As Collection
Set collection = New Collection
collection.Add 5

It’s clear that simply using the following line by itself would not have worked:

Collection.Add 10
Collection.Add 15
Collection.Add 20

But that’s exactly how Visual Basic 6.0 seems to have treated forms: both the class name and instance could be identical. This version, which instantiates a Form1 instance works:

Dim f As Form1
f.Show

But you could also just use the class Form1 as instance variable directly:

Form1.Show

Of course, this ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required