View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Peter T Peter T is offline
external usenet poster
 
Posts: 5,600
Default Nothing Keyword Destories Objects rather than just resetting the variable to an empty variable

ByVal - Creates a whole new replica of the object with all of the same
settings as the object that is being passed onto it


No it doesn't. It creates a new (temporary) pointer to the original
intrinsic object.

As far as the original object's properties are concerned there is no
difference between using ByRef and ByVal.

Regards,
Peter T


"Ronald R. Dodge, Jr." wrote in message
...
The way I understood the ByRef and ByVal are the following:

ByRef - References to the object, and any changes done to the object is
done for any variable referencing to that object, rather it be done in the
original code or in the code referencing to the object.

ByVal - Creates a whole new replica of the object with all of the same
settings as the object that is being passed onto it, but any changes done
to the original object is not reflects in the new object, just like any
changes done in the new object is not reflected in the original object.

Though I haven't fully tested it to be sure with object variables, but
simple data type variables does work like this.

--
Thanks,

Ronald R. Dodge, Jr.
Production Statistician
Master MOUS 2000
"Peter T" <peter_t@discussions wrote in message
...
Afraid I don't follow most of that, maybe a simple example might help.

One thing though, I think you are misunderstanding the difference of
passing an object byref & byval. Either way, any changes to the object's
properties will persist.

The only difference is with byval a new pointer to the original object is
created and passed. This means even if you destroy or reassign the byval
object within the procedure, the original object variable will continue
point to the same object.

Regards,
Peter T



"Ronald R. Dodge, Jr." wrote in message
...
Office XP, SP3 (VBA 6.0)
WIN XP, SP2


I have read over the text dealing with custom objects

According to the text that I have read online from MS themselves, the
keyword "NOTHING" should only destroy the object when there is no other
variable refering to that object. However, as I have learned the hard
way, that is not the case. Any time any variable is set to NOTHING, the
object is destroyed, so any object variable referencing to that object
is then also set to NOTHING.

Example:

PayCode collection has a set of objects containing properties. One of
those PayCode objects is passed onto an Employee Object. It's passed
into the employee object via a property with the object using the ByRef
within the signature line, so if there's any changes to the PayCode
object, it's not only changed within the PayCodes collection, but also
within the Employee's PayCode reference to it.

However, if the Employee Object is set to be destroyed, via the clean up
code, the code should be to set the object variable within the Employee
Object to NOTHING. However, doing that not only does that, but also
set's that particular object within the PayCodes collection to NOTHING
as if the object itself has been destroyed.

How do I resolve this issue, so as I can have it reset only the
variable, not destroy the actual object, but yet, also allow for changes
to carry into the variable when they are done into the main object?

--
Thanks,

Ronald R. Dodge, Jr.
Production Statistician
Master MOUS 2000