Using class modules

  • Thread starter Thread starter Richard
  • Start date Start date
R

Richard

Hi

If I were to use a class module which has functions and procedures I need to
use for the form, can I dim it at 'Declarations' and set it at the Form_Load
Event, then set it to Nothing at Form_Close Event. Will it affect the
performance or memory in any way?

This way I don't need to instantiate (is this the term to use?) it at every
event.

Hope you understand what I am trying to say here..:)

Many thanks in advance
Richard
 
Richard ha scritto:
Hi

If I were to use a class module which has functions and procedures I need to
use for the form, can I dim it at 'Declarations' and set it at the Form_Load
Event, then set it to Nothing at Form_Close Event. Will it affect the
performance or memory in any way?

This way I don't need to instantiate (is this the term to use?) it at every
event.

Hope you understand what I am trying to say here..:)

Many thanks in advance
Richard

In a Form you can create an istance of your class as a Private one, so
you need
to assign it on Load(or other choosen event) and destroy it on
Close...!

Private mCls as ClassName

Private Sub Form_Load()
Set mCls = New ClassName
End sub

Private Sub Form_Close()
Set mCls = Nothing
End sub

In this way the istance of your class is available in the form until
the form is alive...!

@Alex
 
Yes, you can do that. Your app may use slightly more resources, but unless
the object if very large with lots of properties (or complex properties such
as other objects or collections of objects) it is unlikely to be a
significant problem.
 
Thanks Alex

Alessandro Baraldi said:
Richard ha scritto:


In a Form you can create an istance of your class as a Private one, so
you need
to assign it on Load(or other choosen event) and destroy it on
Close...!

Private mCls as ClassName

Private Sub Form_Load()
Set mCls = New ClassName
End sub

Private Sub Form_Close()
Set mCls = Nothing
End sub

In this way the istance of your class is available in the form until
the form is alive...!

@Alex
 
thanks Brendan

Brendan Reynolds said:
Yes, you can do that. Your app may use slightly more resources, but unless
the object if very large with lots of properties (or complex properties
such as other objects or collections of objects) it is unlikely to be a
significant problem.
 
Back
Top