The latter not only declares, but also instantiates the object
DIM A as Class 1
This is just a variable that defines a class, in which case the variable is actually quite a pointer, and the class in the pointer address is not instantiated, or it can be understood as not loading the stack, just an empty address pointer. However, this address pointer can be arbitrarily set to another address.
Like what:
Dim A as Class 1
Dim UU as New Class 1
Set A = UU
and
Dim A As New Class 1
This method can actually be disassembled to look like:
Dim A as Class 1
Set A = new Class 1
The meaning of Dim A as Class 1 we know that is to define a face, and the variable content is a pointer to a class, but because this type does not actually allocate memory and load the stack, so this time the variable is useless, but a pointer to the empty address useless variable.
The new Class 1 is the process of creating a new instance of the class and assigning the newly created instance address to a variable. It can also be understood that a piece of memory is partitioned in memory to fit this class, and the relevant process is loaded into that memory and the memory address is loaded into the stack for a common CPU execution. This well-allocated address handle is the instance handle of this class. That's what a class pointer really stores.
When invoking a property, method, or event of a variable, it is actually the CPU that executes the compiled location code according to the code register and the internal jump, and each instance has a separate block of memory, even though the structure has been, but the content is different, which is the relationship of class and class instantiation.
The understanding in VB, is
Dim A as Class 1 ' is the definition class variable
Set A = new Class 1 ' is the initialization class variable (plus "instance" is more appropriate)
Dim A as New Class 1 ' is to define class variables and initialize class variables at the same time
Because classes must be initialized, classes that are not initialized are not available.
Even if some classes or objects are not initialized by your code, the system or other program will help you initialize it, such as Me, app, Form1 ...
As for the release of the class, that's what it says.
Set A= Nothing
In VB, when the class is set up, the Terminate event is generated in the class, and some resources are freed from the class, and then the memory allocated for the A variable is released.
"Reprint" VB6 inside Dim x As Class1/dim X as new Class1 difference