By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,534 Members | 943 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,534 IT Pros & Developers. It's quick & easy.

class inside a class?

P: n/a
Class A
Oct 31 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a
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.

"HockeyFan" <le**********@gmail.comwrote in message
news:11**********************@m7g2000cwm.googlegro ups.com...
Class A
.
Function A1()
.
Class B
Function test()
How do I reference FunctionA1 here?
End Function

End Class
End Class

Oct 31 '06 #2

P: n/a
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.
Oct 31 '06 #3

P: n/a
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.
Oct 31 '06 #4

P: n/a
"HockeyFan" <le**********@gmail.comwrote in message
news:11**********************@m7g2000cwm.googlegro ups.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.
>

Oct 31 '06 #5

P: n/a
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
"Michael C" wrote:
"HockeyFan" <le**********@gmail.comwrote in message
news:11**********************@m7g2000cwm.googlegro ups.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.


Nov 1 '06 #6

P: n/a
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.
Nov 1 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.