Setting Properties of Class within a Class

  • Thread starter Thread starter Sean
  • Start date Start date
S

Sean

Help, trying to do a simple linked list of a simple object
to store some data. Can VB.NET not handle multiple levels
of objects? My object is just a couple strings, and
NextItem and PrevItem object variables to link the objects
together. So when I am removing one, I want to do a:

Current.PrevItem.NextItem = Current.NextItem
Current.NextItem.PrevItem = Current.PrevItem
Current = Nothing

But it won't let me a the properties beyond one layer.
 
Public Class clsEncounterFormItem
Private m_strItemName As String
Private m_strTabName As String
Private m_intPosition As Integer
Private m_Next As clsEncounterFormItem
Private m_Prev As clsEncounterFormItem

Public Sub New()
m_strItemName = ""
m_strTabName = ""
m_intPosition = 0
m_Next = Nothing
m_Prev = Nothing
End Sub

Public Sub New(ByVal strItemName As String, ByVal
strtabName As String, _
ByVal intPosition As Integer)
m_strItemName = strItemName
m_strTabName = strtabName
m_intPosition = intPosition
m_Next = Nothing
m_Prev = Nothing
End Sub

Property ItemName()
Get
Return m_strItemName
End Get
Set(ByVal Value)
m_strItemName = Value
End Set
End Property

Property TabName()
Get
Return m_strTabName
End Get
Set(ByVal Value)
m_strTabName = Value
End Set
End Property

Property Position()
Get
Return m_intPosition
End Get
Set(ByVal Value)
m_intPosition = Value
End Set
End Property

Property NextItem()
Get
Return m_Next
End Get
Set(ByVal Value)
m_Next = Value
End Set
End Property

Property PrevItem()
Get
Return m_Prev
End Get
Set(ByVal Value)
m_Prev = Value
End Set
End Property

End Class
 
Hey Cor,

haha, usually I find searching the Newsgroups to be a
nightmare of too much information of not at all what I
need almost to the level of searching MSDN....=)

As to the links. I understand how to do a linked list
(hehe, I've been doing them in C++ since I was in diapers
I think). I was just curious if I was doing something
wrong or if there is a reason when doing it I can access
the members of a class within a class.

e.g. CustomClass.CustomClass.Property

My example being my linked list: CurrentListItem's
PreviousItem's NextItem

i.e. Current.PrevItem.NextItem

Trying to figure out if I am doing something wrong or if
you just can't do that in VB.NET like you can in a C++
Language. Thanks for the links though.

Sean
 
Ok... see my comments below...

I am assuming that when you say you cannot see beyond one layer you are
speaking of intellisense (which with a recursive definition such as this
should be infinite)


Sean said:
Public Class clsEncounterFormItem
Private m_strItemName As String
Private m_strTabName As String
Private m_intPosition As Integer
Private m_Next As clsEncounterFormItem
Private m_Prev As clsEncounterFormItem

^^^^
You might get a NullReferenceException thrown eventually because you havent
instiated the classes and nothing is shared.
Public Sub New()
m_strItemName = ""
m_strTabName = ""
m_intPosition = 0
m_Next = Nothing
m_Prev = Nothing
End Sub

Public Sub New(ByVal strItemName As String, ByVal
strtabName As String, _
ByVal intPosition As Integer)
m_strItemName = strItemName
m_strTabName = strtabName
m_intPosition = intPosition
m_Next = Nothing
m_Prev = Nothing
End Sub

Property ItemName()
Get
Return m_strItemName
End Get
Set(ByVal Value)
m_strItemName = Value
End Set
End Property

Property TabName()
Get
Return m_strTabName
End Get
Set(ByVal Value)
m_strTabName = Value
End Set
End Property

Property Position()
Get
Return m_intPosition
End Get
Set(ByVal Value)
m_intPosition = Value
End Set
End Property

Property NextItem()
Get
Return m_Next
End Get
Set(ByVal Value)
m_Next = Value
End Set
End Property

^^^ This is why you can't go any further than 1 "layer"

NextItem isn't defined as anything other than System.Object (default) you
have to declare your property as clsEncounter or whatever it is

so..

Property NextItem as ClsEncounterItem
....
End property

Do the same for next item... hell, do it for all your properties, coding
gets much easier..

Peace
CJ
 
Ok, thanks alot, that is kind of what I was looking for.
Ack, coming from a C++ world here...=) Appreciate it.
 
Back
Top