Smartin wrote:
> sime wrote:
>> That is in a normal module I am guessing. Won't "TheClass" die once the
>> code finishes executing?
>>
>>
>> Smartin wrote:
>>
>>>> I thought I was doing something similar at work, but I will check the
>>>> code tomorrow to be sure and clarify or withdraw my proposition. Thanks
>>>> for the heads-up.
>>>>
>>> My error, the declaration I am using is actually
>>>
>>> Option Compare Database
>>> Option Explicit
>>>
>>> Public TheClass As New MyClass
>>> --------------------------------------
>>>
>>> Works great. The class is accessible to other modules and forms.
>>>
>>> --
>>> Smartin
>>
>
> Yes, the declaration is in a normal module. Without meaning to be
> argumentative, explain when should object TheClass die? The module does
> not "close". It merely exists, and no code is fired to instantiate the
> object. In better days I could probably have given a better explanation.
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=13794
Reference:: Sikh Philosophy Network http://www.sikhphilosophy.net/showthread.php?t=13794
> I hope this makes sense.
>
> I will look into this a little further to be sure, but AFAICT the
> instantiation of the class persists as long as the application is open.
>
> Kind Regards,
Just to follow up and (hopefully) clarify, a publicly declared object is
accessible to the application for the life of the application. Unless,
of course, you set the object to Nothing.
Think of a publicly declared variable. It doesn't go away even though
the code asking for it is in another class/form/module.
Getting off topic somewhat, I would be interested to hear comments on
the virtues and pitfalls of using a class vs. a collection of variables
and functions in a module.
Personally, when I have a group of processes I want to apply to a
"thing" I like to create a class for it. I can swiftly reuse the code if
I need to use the "thing" in another application -- I simply drop in its
class module.
In the long run I find it is much easier to have the thing's methods and
properties on hand by typing a dot, rather than try to recall what Subs
and Functions are available. Plus, if I want to have multiple "things"
at the same time, a class makes this a snap.
For instance one "thing" I've been reusing quite a bit lately is
basically a text container I use to build up email messages in Access.
VBA and A97 do not provide a very robust collection of text manipulation
features, so I built functionality into the class like search and
replace, a tabulation mechanism for aligning columns of data, append,
automatic insertion of CrLf, etc. This reduces the amount of code I have
to write later -- and cleans up the code considerably.
HTH
--
Smartin