Hi Leith!
Ok....let me share my understanding as it is at the moment. If it disagrees with your view, then don't think I am dead set on defending my point of view. Just help me see more clearly.
As far as I can see, VBA mixes up several concepts.
Declaring....and scope.
Declaring, to me, is an instruction to a VBA compiler to associate a variable with a datastructure. Data structures do not occupy memory. they are merely a scheme that states that if this variable actually existed, then use the scheme to store
data of interest. Declaring indicates nothing about actual memory used. Merely the amount of memory and the way it is
organized if it did exist. Dim A as long tells the compiler that if A is encountered, it needs x bytes and is read in a certain manner. Dim A as SpecialObject is no different.
My interpretation of Chip Pearson explanations suggests that when the compiled code is run and encounters a statement with the variable indicated above as follows: A = ASpecialObject then the run time code (1) copies the data from the datastructure of ASpecialObject and (2) assigns physical memory to A that conforms to the needs of A (not ASpecialObject) and places data in A according to the datastructure assigned to A. In summary: if both data structures are identical (which is checked at compile time). then memory is assigned at run time in the proper manner while executing the above statement.
now scope....(the ability to see a specific variable inside a procedure, or outside of a procedure but still within a module, or outside of a module but still within a project, or outside a project and seen by all workbooks)....is interestingly not assigned at time of assigning memory!!!!! but at compile time. I suspect the compiler looks for special key words (as in private or public) in a declaration and the location of a declaration and at compile time determines the scope of a variable.
Thus in my original example, an object created in its own class module must be declared in my main program at the top of the module that my main procedure is written in ....and that defines its scope (I suspect).
It is actually created in the subroutine that I mentioned but because of the location of the declaration, the compiler ensures it is seen global to all procedures within the module regardless of where memory is actually assigned to the variable.
what do you think?
Bookmarks