Home All Groups Group Topic Archive Search About

class inside a class?

Author
31 Oct 2006 7:59 PM
HockeyFan
Class A
  .
  Function A1()
  .
Class B
  Function test()
     How do I reference FunctionA1 here?
  End Function

End Class
End Class

Author
31 Oct 2006 8:54 PM
Miro
Would you not have to make a class A within class b
<written in text not editor >

Dim cHi As New Class A

cHi.A1

----
Or...
Make the function public ?

***Im new at this too but maybe you have to even do a

Dim cClassB As New Class B  '(within Class A)
and call Class b from within A ?

Whats that function do ?
Maybe you just need a module with a public function that can be called from
anywhere you want?

M.



Show quoteHide quote
"HockeyFan" <les.stock***@gmail.com> wrote in message
news:1162324774.085273.289350@m7g2000cwm.googlegroups.com...
> Class A
>  .
>  Function A1()
>  .
> Class B
>  Function test()
>     How do I reference FunctionA1 here?
>  End Function
>
> End Class
> End Class
>
Author
31 Oct 2006 9:19 PM
Mattias Sjögren
>     How do I reference FunctionA1 here?

Like any other method, you either need an instance of the containing
class (an A object), or make the method Shared so it can be called
witout an instance.


Mattias

--
Mattias Sjögren [C# MVP]  mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Author
31 Oct 2006 10:00 PM
Göran_Andersson
HockeyFan wrote:
> Class A
>   .
>   Function A1()
>   .
> Class B
>   Function test()
>      How do I reference FunctionA1 here?
>   End Function
>
> End Class
> End Class
>

As you would from anywhere. As the method is not static (Shared in VB),
you need an instance of the A class to use it.
Author
31 Oct 2006 11:30 PM
Michael C
"HockeyFan" <les.stock***@gmail.com> wrote in message
news:1162324774.085273.289350@m7g2000cwm.googlegroups.com...
> Class A
>  .
>  Function A1()
>  .
> Class B
>  Function test()
>     How do I reference FunctionA1 here?
>  End Function
>
> End Class
> End Class

Just to add to what other's have said, it looks like from your question that
you consider instances of ClassA and ClassB to be somehow related (or even
the same thing). They are seperate classes just like any other classes but
with some special considerations, eg B can call A's private parts.

Show quoteHide quote
>
Author
1 Nov 2006 12:24 AM
Dennis
Not sure if the below will work or not but if not, I'm sure someone will let
me know!

Class A
   Private C1 as Class A
   Public Sub New()
      A = Me
   End Sub

   Public Function A1() as Something
      ...
   End Function

   Class B
     Function test()
        Dim var as  Something = C.A1()
     End Function

    End Class
End Class
>


--
Dennis in Houston


Show quoteHide quote
"Michael C" wrote:

> "HockeyFan" <les.stock***@gmail.com> wrote in message
> news:1162324774.085273.289350@m7g2000cwm.googlegroups.com...
> > Class A
> >  .
> >  Function A1()
> >  .
> > Class B
> >  Function test()
> >     How do I reference FunctionA1 here?
> >  End Function
> >
> > End Class
> > End Class
>
> Just to add to what other's have said, it looks like from your question that
> you consider instances of ClassA and ClassB to be somehow related (or even
> the same thing). They are seperate classes just like any other classes but
> with some special considerations, eg B can call A's private parts.
>
> >
>
>
>
Author
1 Nov 2006 2:21 PM
Phill W.
HockeyFan wrote:
> Class A
>   .
>   Function A1()
>   .
> Class B
>   Function test()
>      How do I reference FunctionA1 here?
>   End Function
>
> End Class
> End Class
>

The inner class [instance] requires an instance of the parent object to
work with.  Generally, I do it this way :

Class A
    Function A1() as whatever
    End Function

    Class B
       ' 'A' can create 'B's, but the Outside World cannot.
       Friend Sub New( ByVal parent as A )
          m_parent = parent
       End Sub

       Function test() as whatever
          Return m_parent.A1()
       End Function

       Private m_parent As A = Nothing

    End Class
End Class

HTH,
    Phill  W.