Hi,
A form is a class. I make the difference between a class, kind of a blue
print plan, and an object created from the class, kind of a realization made
from the blue print plan.
Dim a As New Car
Dim b As New Car
would NOT duplicate the code in class Car, but would duplicate the
member variables of the class. In memory, we would have, if we simplify:
... [Data for car a] ... [Data for car b] .... [ code for procedure in
class Car ] ....
The code appear just ONCE in memory, even if we have two objects. When
the code in a procedure in class Car runs, it may see:
Me.Color = brown
and then, since the code is NOT associated to any specific object, it has to
relay on "Me", a reference to the data to be modified, to know if it should
update the data for car a, or the data for car b, as appropriate,... or the
data for car c if a third car object is created.
Sure, in general, a form has only one instance, but a form is a class
and we can create many instances of the same form, if we really want it:
Dim i As long
Dim b( 1 to 10) As Form_Form1
For i = 1 to 10
Set b(i)=New Form_Form1
b(i).Visible = true
Next i
MsgBox "Should have 10 forms Form1 now visible!"
( that assumes you have a Form1 with code behind it).
There would be just one sample of the code for the 10 objects from
Form_Form1. When the line of code
b(i).Visible=True
is executed, the internal code does the same trick as you would, using "Me"
(or the C++ pointer "this") to make THE EXACT object visible...
Since the CODE is not repeated, in memory, for each object... the code,
common to all objects of the same class, is in need of a reference to know
the data it should use, "Me" does supply this reference.
Hoping it may help,
Vanderghast, Access MVP