class inside a class?

  • Thread starter Thread starter HockeyFan
  • Start date Start date
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.
 
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
 
HockeyFan said:
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.
 
HockeyFan said:
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.
 
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
 
HockeyFan said:
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.
 
Back
Top