Home All Groups Group Topic Archive Search About

Private objects cannot be used ... as parameters..

Author
18 May 2009 8:58 PM
MP
Regarding this compile error
"Private object modules cannot be used in public object modules as
parameters or ...etc"

Given the desire to use an object as a parameter...
Sub Main
    Dim oParam as cUsefulObject
    Set oParam = CreateParameterObject()

    Dim oSomeObj as cOtherObject
    Set oSomeObj = CreateOtherObject

    oSomeObj.Init(oParam)
    ...
End Sub

If cOtherObject.Init() is defined as
Public Sub Init(oParam as cUsefulObject)
....then of course I get the compile error

If cOtherObject.Init() is defined as
Public Sub Init(oInParam as Object)
  Dim oParam as cUsefulObject
    Set oParam = oInParam

....then I can use it but it seems a weird workaround that the receiving
object has to duplicate the dimming and setting  .... but is that a "proper"
way to get around the problem?

ah..I just remembered the instancing properties of a class...
so if this is a std exe project I can set the instancing of cUsefulObject to
PublicNotCreatable and it would work...is that the better path?

Thanks
Mark

Author
18 May 2009 9:24 PM
Nobody
Use "Friend" instead of "Public".

Private does not allow the method to be seen in the project nor outside the
project.
Friend allows the method to be seen in the project, but not outside the
project.
Public allows the method to be seen in the project and outside the project.

Even though you maybe using a standard EXE, sometimes the compiler objects
to using "Public", so use "Friend" instead.
Author
19 May 2009 1:57 AM
MP
Show quote Hide quote
"Nobody" <nob***@nobody.com> wrote in message
news:uBuFp8$1JHA.3988@TK2MSFTNGP05.phx.gbl...
> Use "Friend" instead of "Public".
>
> Private does not allow the method to be seen in the project nor outside
the
> project.
> Friend allows the method to be seen in the project, but not outside the
> project.
> Public allows the method to be seen in the project and outside the
project.
>
> Even though you maybe using a standard EXE, sometimes the compiler objects
> to using "Public", so use "Friend" instead.
>


Thanks,
Have read about friend for years but never used it...
will give it a go
Mark