|
-
Jun 17th, 2011, 07:24 AM
#1
Re: Declaring ClassModule as public
Yes you can declare it as Public in a Bas Module and use it
anywhere in your project. However there is a caveat: VB
does not allow Public WithEvents in a module. So if the class
has Events you will need to declare the class WithEvents in
each module where you need it. Or you could declare it
as Public WithEvents in your main form and refer to that
instance in the other modules.
-
Jun 17th, 2011, 02:30 PM
#2
Thread Starter
Member
Re: Declaring ClassModule as public
RhinoBull, VBClassicRocks Thanks a lot people
VBClassicRocks, thanks for the info....Actually there is no events in this class
"'in the module
Option Explicit
Public myClass As Class1
'elsewhere in your code - perhaps main form load event
Set myClass = New Class1 '<<< do it only once when program starts"
What about declaring the class-module in a module like this:
Public myClass As New Class1
and when exiting program. (set myclass = nothing)
By doing so i can avoid "Set myClass = New Class1" every time when i am calling this class...
Is that ok?
----------------------------------------------------------------------------------------------------------------------------------------------------
"Pasting somebody's Code or Link is easy; Spending some time and addressing the real issue & putting our own ideas and codes is difficult"
----------------------------------------------------------------------------------------------------------------------------------------------------
-
Jun 17th, 2011, 03:56 PM
#3
Re: Declaring ClassModule as public
 Originally Posted by WeeBee
What about declaring the class-module in a module like this:
Public myClass As New Class1
and when exiting program. (set myclass = nothing)
By doing so i can avoid "Set myClass = New Class1" every time when i am calling this class...
Is that ok?
Not really, it may create you more troubles than you can wish for.
Forum has few discussions on the subject so if interested try searching for something like "why dim as new is a bad idea".
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|