Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 134
Default Private vs Public Class Modules

VB6.0
Excel 2002, SP3

How can I get private and public instancing class modules to communicate
with each other?

Example

I am creating a program that using a class name of "TempEmployee" (Need
multiple instances of this class, thus private instance is the only instance
available) and a collection class name of "TempEmployees" (This object, only
need one instance of it and I would like to be able to reference to it from
within any other module within the project, but when I attempt to set a
public variable to it, it comes back stated can't do it as a public variable
can't contain a private class module). I also get the same basic issue with
I attempt to combine public and private classes into each other. What is
the best way to resolve this issue so as I don't have to do so much coding
and work arounds?

One way, I could create properties in so many other objects as a reference
to this one object, on the other hand, that in itself seems to be a lot of
work and could lead to possible overlooking. What is a good book on this
sort of VBA Class module coding?

--
Thanks,

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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,420
Default Private vs Public Class Modules

Ronald,

If you want multiple instances of a class, why not create a collection
class? It does mean that you have to code the .Add and .Remove methods, but
it is not difficult.

--
__________________________________
HTH

Bob

"Ronald R. Dodge, Jr." wrote in message
...
VB6.0
Excel 2002, SP3

How can I get private and public instancing class modules to communicate
with each other?

Example

I am creating a program that using a class name of "TempEmployee" (Need
multiple instances of this class, thus private instance is the only
instance available) and a collection class name of "TempEmployees" (This
object, only need one instance of it and I would like to be able to
reference to it from within any other module within the project, but when
I attempt to set a public variable to it, it comes back stated can't do it
as a public variable can't contain a private class module). I also get
the same basic issue with I attempt to combine public and private classes
into each other. What is the best way to resolve this issue so as I don't
have to do so much coding and work arounds?

One way, I could create properties in so many other objects as a reference
to this one object, on the other hand, that in itself seems to be a lot of
work and could lead to possible overlooking. What is a good book on this
sort of VBA Class module coding?

--
Thanks,

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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 134
Default Private vs Public Class Modules

If you notice in the example that I stated, the TempEmployees is the
collection class while the TempEmployee is the Individual object class
similar to the Worksheets collection class with the Worksheet individual
object class.

The TempEmployees collection class is a holder for all of the individual
TempEmployee object classes (One per temporary employee). As such, there
only needs to be one TempEmployees collection object in memory vs several
TempEmployee individual objects in memory.

The problem I'm having, I want to expose this TempEmployees Object to be
visible across the entire project, not just within the module. As it
currently stands, I can only think of using either properties or methods to
set that, which seems to be a lot of work (when you have to do it across
several different classes) that would save some time and prevent possible
overlooking if it could just be set to a variable that could be seen across
the project (I.e. Within VB6, you use the Friend keyword which allows such
cases to be seen outside of the module the code in it, but not outside of
the project the code is in.)

--
Thanks,

Ronald R. Dodge, Jr.
Production Statistician
Master MOUS 2000
"Bob Phillips" wrote in message
...
Ronald,

If you want multiple instances of a class, why not create a collection
class? It does mean that you have to code the .Add and .Remove methods,
but it is not difficult.

--
__________________________________
HTH

Bob

"Ronald R. Dodge, Jr." wrote in message
...
VB6.0
Excel 2002, SP3

How can I get private and public instancing class modules to communicate
with each other?

Example

I am creating a program that using a class name of "TempEmployee" (Need
multiple instances of this class, thus private instance is the only
instance available) and a collection class name of "TempEmployees" (This
object, only need one instance of it and I would like to be able to
reference to it from within any other module within the project, but when
I attempt to set a public variable to it, it comes back stated can't do
it as a public variable can't contain a private class module). I also
get the same basic issue with I attempt to combine public and private
classes into each other. What is the best way to resolve this issue so
as I don't have to do so much coding and work arounds?

One way, I could create properties in so many other objects as a
reference to this one object, on the other hand, that in itself seems to
be a lot of work and could lead to possible overlooking. What is a good
book on this sort of VBA Class module coding?

--
Thanks,

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





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,420
Default Private vs Public Class Modules

Ronald,

I am not getting this. I have just created a class and a collection class,
and setup multiple instances of the first. My collection class variable was
a public variable.

In another module, I accessed this public collection class variable no
problems.

I guess I am not getting the problem?

--
__________________________________
HTH

Bob

"Ronald R. Dodge, Jr." wrote in message
...
If you notice in the example that I stated, the TempEmployees is the
collection class while the TempEmployee is the Individual object class
similar to the Worksheets collection class with the Worksheet individual
object class.

The TempEmployees collection class is a holder for all of the individual
TempEmployee object classes (One per temporary employee). As such, there
only needs to be one TempEmployees collection object in memory vs several
TempEmployee individual objects in memory.

The problem I'm having, I want to expose this TempEmployees Object to be
visible across the entire project, not just within the module. As it
currently stands, I can only think of using either properties or methods
to set that, which seems to be a lot of work (when you have to do it
across several different classes) that would save some time and prevent
possible overlooking if it could just be set to a variable that could be
seen across the project (I.e. Within VB6, you use the Friend keyword which
allows such cases to be seen outside of the module the code in it, but not
outside of the project the code is in.)

--
Thanks,

Ronald R. Dodge, Jr.
Production Statistician
Master MOUS 2000
"Bob Phillips" wrote in message
...
Ronald,

If you want multiple instances of a class, why not create a collection
class? It does mean that you have to code the .Add and .Remove methods,
but it is not difficult.

--
__________________________________
HTH

Bob

"Ronald R. Dodge, Jr." wrote in message
...
VB6.0
Excel 2002, SP3

How can I get private and public instancing class modules to communicate
with each other?

Example

I am creating a program that using a class name of "TempEmployee" (Need
multiple instances of this class, thus private instance is the only
instance available) and a collection class name of "TempEmployees" (This
object, only need one instance of it and I would like to be able to
reference to it from within any other module within the project, but
when I attempt to set a public variable to it, it comes back stated
can't do it as a public variable can't contain a private class module).
I also get the same basic issue with I attempt to combine public and
private classes into each other. What is the best way to resolve this
issue so as I don't have to do so much coding and work arounds?

One way, I could create properties in so many other objects as a
reference to this one object, on the other hand, that in itself seems to
be a lot of work and could lead to possible overlooking. What is a good
book on this sort of VBA Class module coding?

--
Thanks,

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







  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 134
Default Private vs Public Class Modules

If I set the class to public, I get the below message at compile time:

Private object modules cannot be used in public object modules as parameters
or return types for public procedures, as public data members, or as fields
of public user defined types

and it highlights the following signature line within the public collection
class:

Public Property Get prp_ro_TempEmployeeByID(ByVal l_strIdentificationCode As
String) As clsTempEmployee

As for using "As Object" in place of "As clsTempEmployee", I don't
particularly care for doing that either as that gets away from good
programming practices.


Now when I have the collection class as private, it no longer errors out
during compilation time.

--
Thanks,

Ronald R. Dodge, Jr.
Production Statistician
Master MOUS 2000
"Bob Phillips" wrote in message
...
Ronald,

I am not getting this. I have just created a class and a collection class,
and setup multiple instances of the first. My collection class variable
was a public variable.

In another module, I accessed this public collection class variable no
problems.

I guess I am not getting the problem?

--
__________________________________
HTH

Bob

"Ronald R. Dodge, Jr." wrote in message
...
If you notice in the example that I stated, the TempEmployees is the
collection class while the TempEmployee is the Individual object class
similar to the Worksheets collection class with the Worksheet individual
object class.

The TempEmployees collection class is a holder for all of the individual
TempEmployee object classes (One per temporary employee). As such, there
only needs to be one TempEmployees collection object in memory vs several
TempEmployee individual objects in memory.

The problem I'm having, I want to expose this TempEmployees Object to be
visible across the entire project, not just within the module. As it
currently stands, I can only think of using either properties or methods
to set that, which seems to be a lot of work (when you have to do it
across several different classes) that would save some time and prevent
possible overlooking if it could just be set to a variable that could be
seen across the project (I.e. Within VB6, you use the Friend keyword
which allows such cases to be seen outside of the module the code in it,
but not outside of the project the code is in.)

--
Thanks,

Ronald R. Dodge, Jr.
Production Statistician
Master MOUS 2000
"Bob Phillips" wrote in message
...
Ronald,

If you want multiple instances of a class, why not create a collection
class? It does mean that you have to code the .Add and .Remove methods,
but it is not difficult.

--
__________________________________
HTH

Bob

"Ronald R. Dodge, Jr." wrote in message
...
VB6.0
Excel 2002, SP3

How can I get private and public instancing class modules to
communicate with each other?

Example

I am creating a program that using a class name of "TempEmployee" (Need
multiple instances of this class, thus private instance is the only
instance available) and a collection class name of "TempEmployees"
(This object, only need one instance of it and I would like to be able
to reference to it from within any other module within the project, but
when I attempt to set a public variable to it, it comes back stated
can't do it as a public variable can't contain a private class module).
I also get the same basic issue with I attempt to combine public and
private classes into each other. What is the best way to resolve this
issue so as I don't have to do so much coding and work arounds?

One way, I could create properties in so many other objects as a
reference to this one object, on the other hand, that in itself seems
to be a lot of work and could lead to possible overlooking. What is a
good book on this sort of VBA Class module coding?

--
Thanks,

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











  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,420
Default Private vs Public Class Modules

Ronald,

Nowhere have I suggested that you set the class instancing type to public, I
used private in both mine. I was talking about creating the collection class
variable as public.

Perhaps it would be best to give the whole code for us to try.

--
__________________________________
HTH

Bob

"Ronald R. Dodge, Jr." wrote in message
...
If I set the class to public, I get the below message at compile time:

Private object modules cannot be used in public object modules as
parameters or return types for public procedures, as public data members,
or as fields of public user defined types

and it highlights the following signature line within the public
collection class:

Public Property Get prp_ro_TempEmployeeByID(ByVal l_strIdentificationCode
As String) As clsTempEmployee

As for using "As Object" in place of "As clsTempEmployee", I don't
particularly care for doing that either as that gets away from good
programming practices.


Now when I have the collection class as private, it no longer errors out
during compilation time.

--
Thanks,

Ronald R. Dodge, Jr.
Production Statistician
Master MOUS 2000
"Bob Phillips" wrote in message
...
Ronald,

I am not getting this. I have just created a class and a collection
class, and setup multiple instances of the first. My collection class
variable was a public variable.

In another module, I accessed this public collection class variable no
problems.

I guess I am not getting the problem?

--
__________________________________
HTH

Bob

"Ronald R. Dodge, Jr." wrote in message
...
If you notice in the example that I stated, the TempEmployees is the
collection class while the TempEmployee is the Individual object class
similar to the Worksheets collection class with the Worksheet individual
object class.

The TempEmployees collection class is a holder for all of the individual
TempEmployee object classes (One per temporary employee). As such,
there only needs to be one TempEmployees collection object in memory vs
several TempEmployee individual objects in memory.

The problem I'm having, I want to expose this TempEmployees Object to be
visible across the entire project, not just within the module. As it
currently stands, I can only think of using either properties or methods
to set that, which seems to be a lot of work (when you have to do it
across several different classes) that would save some time and prevent
possible overlooking if it could just be set to a variable that could be
seen across the project (I.e. Within VB6, you use the Friend keyword
which allows such cases to be seen outside of the module the code in it,
but not outside of the project the code is in.)

--
Thanks,

Ronald R. Dodge, Jr.
Production Statistician
Master MOUS 2000
"Bob Phillips" wrote in message
...
Ronald,

If you want multiple instances of a class, why not create a collection
class? It does mean that you have to code the .Add and .Remove methods,
but it is not difficult.

--
__________________________________
HTH

Bob

"Ronald R. Dodge, Jr." wrote in message
...
VB6.0
Excel 2002, SP3

How can I get private and public instancing class modules to
communicate with each other?

Example

I am creating a program that using a class name of "TempEmployee"
(Need multiple instances of this class, thus private instance is the
only instance available) and a collection class name of
"TempEmployees" (This object, only need one instance of it and I would
like to be able to reference to it from within any other module within
the project, but when I attempt to set a public variable to it, it
comes back stated can't do it as a public variable can't contain a
private class module). I also get the same basic issue with I attempt
to combine public and private classes into each other. What is the
best way to resolve this issue so as I don't have to do so much coding
and work arounds?

One way, I could create properties in so many other objects as a
reference to this one object, on the other hand, that in itself seems
to be a lot of work and could lead to possible overlooking. What is a
good book on this sort of VBA Class module coding?

--
Thanks,

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











  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,420
Default Private vs Public Class Modules

So does this mean that you are sorted now?

--
__________________________________
HTH

Bob

"Ronald R. Dodge, Jr." wrote in message
...
Okay, this is odd. The last time when I attempted to do just that within
a standard module, it gave me that same basic error message about me not
being able to assign a private class to a public variable. I do it again
this time around and it doesn't error out as I had expected based on
previous experience.
--
Thanks,

Ronald R. Dodge, Jr.
Production Statistician
Master MOUS 2000
"Bob Phillips" wrote in message
...

"Ronald R. Dodge, Jr." wrote in message
...
As far as declaring variables within class modules as public variables,
that's making implicit statements and not really good programming
practices. I rather use Property statements to expose such things than
to use the Public keyword within variable declarations. The only place
where I use public declarations like that are within standard modules,
which I have attempted to do but still get the same basic issue as I get
when attempting to turn the collection class as a public instance.



Whilst I did not suggest this, there is nothing wrong with it. A public
variable in a class module is a property, it is just an implicit
read/write property.

What I said is to declare the collection class variable as public, that
is the variable in the usage code that links to your collection class.
Somewhere in a standard module I assume you have some code similar in
logic to this pseudo code

Public MyCollClass As CollClass

Public Sub Do Stuff()
Dim MyBasicClass As BasicClass

Set MyCollClass = New CollClass

Set MyBasicClass = New BasicClass
With MyBasicClass

.'populate class instance #1
MyCollClass .Add MyBasicClass
End With
Set MyBasicClass = Nothing

Set MyBasicClass = New BasicClass
With MyBasicClass

.'populate class instance #2
MyCollClass .Add MyBasicClass
End With
Set MyBasicClass = Nothing

Set MyBasicClass = New BasicClass
With MyBasicClass

.'populate class instance #3
MyCollClass .Add MyBasicClass
End With
Set MyBasicClass = Nothing

End Sub


Then you can access each instance through the collection class


This sort of declaration is more or less like the same things as using
the "New" keyword within variable declarations rather than using it
within the procedures when creating new objects. You may think I'm
being harsh about sticking to good programming practices, but I have ran
into too many problems in the past and will only stick to these good
programming practices to avoid many of such issues down the road.



Not at all, I just have no idea how you are doing it. I have outlined
above how I do it.


The other thing, I would rather have the class seen by the entire
project than the collection data type variable itself. Reason being,
the class itself has a few things that the collection data type variable
doesn't have. Not only that, but there's greater control over the
variables within the class when it's handled properly within the class.
When variables starts getting handled outside of the class, too many
issues are of concern and I don't care for the risks involved with doing
that. Memory leaks is one such issue like that.



This I really don't understand. You expose the class through a variable.
You have to provide some means of referencing the class.

I use this technique regularly, and am not aware of any such problems.





  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 134
Default Private vs Public Class Modules

Hopefully, but if this issue comes up again using in this sort of manner, I
will have to post back with the exact message. I have no idea why it failed
on me in prior attempts as I don't recall doing anything different from this
time around.

--
Thanks,

Ronald R. Dodge, Jr.
Production Statistician
Master MOUS 2000
"Bob Phillips" wrote in message
...
So does this mean that you are sorted now?

--
__________________________________
HTH

Bob

"Ronald R. Dodge, Jr." wrote in message
...
Okay, this is odd. The last time when I attempted to do just that within
a standard module, it gave me that same basic error message about me not
being able to assign a private class to a public variable. I do it again
this time around and it doesn't error out as I had expected based on
previous experience.
--
Thanks,

Ronald R. Dodge, Jr.
Production Statistician
Master MOUS 2000
"Bob Phillips" wrote in message
...

"Ronald R. Dodge, Jr." wrote in message
...
As far as declaring variables within class modules as public variables,
that's making implicit statements and not really good programming
practices. I rather use Property statements to expose such things than
to use the Public keyword within variable declarations. The only place
where I use public declarations like that are within standard modules,
which I have attempted to do but still get the same basic issue as I
get when attempting to turn the collection class as a public instance.


Whilst I did not suggest this, there is nothing wrong with it. A public
variable in a class module is a property, it is just an implicit
read/write property.

What I said is to declare the collection class variable as public, that
is the variable in the usage code that links to your collection class.
Somewhere in a standard module I assume you have some code similar in
logic to this pseudo code

Public MyCollClass As CollClass

Public Sub Do Stuff()
Dim MyBasicClass As BasicClass

Set MyCollClass = New CollClass

Set MyBasicClass = New BasicClass
With MyBasicClass

.'populate class instance #1
MyCollClass .Add MyBasicClass
End With
Set MyBasicClass = Nothing

Set MyBasicClass = New BasicClass
With MyBasicClass

.'populate class instance #2
MyCollClass .Add MyBasicClass
End With
Set MyBasicClass = Nothing

Set MyBasicClass = New BasicClass
With MyBasicClass

.'populate class instance #3
MyCollClass .Add MyBasicClass
End With
Set MyBasicClass = Nothing

End Sub


Then you can access each instance through the collection class


This sort of declaration is more or less like the same things as using
the "New" keyword within variable declarations rather than using it
within the procedures when creating new objects. You may think I'm
being harsh about sticking to good programming practices, but I have
ran into too many problems in the past and will only stick to these
good programming practices to avoid many of such issues down the road.


Not at all, I just have no idea how you are doing it. I have outlined
above how I do it.


The other thing, I would rather have the class seen by the entire
project than the collection data type variable itself. Reason being,
the class itself has a few things that the collection data type
variable doesn't have. Not only that, but there's greater control over
the variables within the class when it's handled properly within the
class. When variables starts getting handled outside of the class, too
many issues are of concern and I don't care for the risks involved with
doing that. Memory leaks is one such issue like that.


This I really don't understand. You expose the class through a variable.
You have to provide some means of referencing the class.

I use this technique regularly, and am not aware of any such problems.







  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,420
Default Private vs Public Class Modules

If it does happen again, perhaps mail me the workbook?

--
__________________________________
HTH

Bob

"Ronald R. Dodge, Jr." wrote in message
...
Hopefully, but if this issue comes up again using in this sort of manner,
I will have to post back with the exact message. I have no idea why it
failed on me in prior attempts as I don't recall doing anything different
from this time around.

--
Thanks,

Ronald R. Dodge, Jr.
Production Statistician
Master MOUS 2000
"Bob Phillips" wrote in message
...
So does this mean that you are sorted now?

--
__________________________________
HTH

Bob

"Ronald R. Dodge, Jr." wrote in message
...
Okay, this is odd. The last time when I attempted to do just that
within a standard module, it gave me that same basic error message about
me not being able to assign a private class to a public variable. I do
it again this time around and it doesn't error out as I had expected
based on previous experience.
--
Thanks,

Ronald R. Dodge, Jr.
Production Statistician
Master MOUS 2000
"Bob Phillips" wrote in message
...

"Ronald R. Dodge, Jr." wrote in message
...
As far as declaring variables within class modules as public
variables, that's making implicit statements and not really good
programming practices. I rather use Property statements to expose such
things than to use the Public keyword within variable declarations.
The only place where I use public declarations like that are within
standard modules, which I have attempted to do but still get the same
basic issue as I get when attempting to turn the collection class as a
public instance.


Whilst I did not suggest this, there is nothing wrong with it. A public
variable in a class module is a property, it is just an implicit
read/write property.

What I said is to declare the collection class variable as public, that
is the variable in the usage code that links to your collection class.
Somewhere in a standard module I assume you have some code similar in
logic to this pseudo code

Public MyCollClass As CollClass

Public Sub Do Stuff()
Dim MyBasicClass As BasicClass

Set MyCollClass = New CollClass

Set MyBasicClass = New BasicClass
With MyBasicClass

.'populate class instance #1
MyCollClass .Add MyBasicClass
End With
Set MyBasicClass = Nothing

Set MyBasicClass = New BasicClass
With MyBasicClass

.'populate class instance #2
MyCollClass .Add MyBasicClass
End With
Set MyBasicClass = Nothing

Set MyBasicClass = New BasicClass
With MyBasicClass

.'populate class instance #3
MyCollClass .Add MyBasicClass
End With
Set MyBasicClass = Nothing

End Sub


Then you can access each instance through the collection class


This sort of declaration is more or less like the same things as using
the "New" keyword within variable declarations rather than using it
within the procedures when creating new objects. You may think I'm
being harsh about sticking to good programming practices, but I have
ran into too many problems in the past and will only stick to these
good programming practices to avoid many of such issues down the road.


Not at all, I just have no idea how you are doing it. I have outlined
above how I do it.


The other thing, I would rather have the class seen by the entire
project than the collection data type variable itself. Reason being,
the class itself has a few things that the collection data type
variable doesn't have. Not only that, but there's greater control over
the variables within the class when it's handled properly within the
class. When variables starts getting handled outside of the class, too
many issues are of concern and I don't care for the risks involved
with doing that. Memory leaks is one such issue like that.


This I really don't understand. You expose the class through a
variable. You have to provide some means of referencing the class.

I use this technique regularly, and am not aware of any such problems.









Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
difference between a private sub and a public function? Dave F Excel Discussion (Misc queries) 4 March 16th 07 07:38 PM
Class modules: parametrize class object fields Jean-Pierre Bidon Excel Programming 11 August 31st 06 02:49 PM
Public, Private, Event modules, Forms modules,,, Jim May Excel Programming 11 October 31st 05 03:12 AM
Basic question - modules and class modules - what's the difference? Mark Stephens[_3_] Excel Programming 9 May 8th 05 11:48 AM
public but private variables No Name Excel Programming 2 May 19th 04 12:41 PM


All times are GMT +1. The time now is 10:33 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"