Hi All, I am showing my age here...
I am creating a number of instances of a class (from a different module). at the point of creating the new instance of the class i am passing the New() Sub for the class some information to use / assign to the new instance of the class. I am struggling because all of the 16 instances of the class i am creating are all ending up references one set of Dictionaries, somewhere in memory. I want the each new instance of the Container class to have their .Children, .Index and .Technical dictionaries contain the information that was sent...not the very last set of information that the For Loop happened to contain. Here is what i have:
...Calling Module / Sub
... For Each aSomething In colSomething
'''build lTechnical and lIndex and lChildren local dictionaries...that aSomething has
Containers.Add(strRecordID, New Container(strRecordID, lTechnical, lIndex, lChildren))
... Next
'''later on i am getting all of the Container instances having the same Technical, Children and Index...based on the last aSomething
...End Calling Module / Sub
Public Class Container
Public Property ID As String
Public Property Children As Dictionary(Of String, String)
Public Property Index As Dictionary(Of String, String)
Public Property Technical As Dictionary(Of String, String)
Public Sub New(ByVal strID As String, ByVal lTechnical As Dictionary(Of String, String), ByVal lIndex As Dictionary(Of String, String), ByVal lChildren As Dictionary(Of String, String))
Me.ID = strID
'Me.Technical = New Dictionary(Of String, String)
'Me.Index = New Dictionary(Of String, String)
'Me.Children = New Dictionary(Of String, String)
Me.Technical = lTechnical
Me.Index = lIndex
Me.Children = lChildren
End Sub
End Class
I Hear, I Forget
I See, I Remember
I Do, I Understand
Ronald McDonald
I am creating a number of instances of a class (from a different module). at the point of creating the new instance of the class i am passing the New() Sub for the class some information to use / assign to the new instance of the class. I am struggling because all of the 16 instances of the class i am creating are all ending up references one set of Dictionaries, somewhere in memory. I want the each new instance of the Container class to have their .Children, .Index and .Technical dictionaries contain the information that was sent...not the very last set of information that the For Loop happened to contain. Here is what i have:
...Calling Module / Sub
... For Each aSomething In colSomething
'''build lTechnical and lIndex and lChildren local dictionaries...that aSomething has
Containers.Add(strRecordID, New Container(strRecordID, lTechnical, lIndex, lChildren))
... Next
'''later on i am getting all of the Container instances having the same Technical, Children and Index...based on the last aSomething
...End Calling Module / Sub
Public Class Container
Public Property ID As String
Public Property Children As Dictionary(Of String, String)
Public Property Index As Dictionary(Of String, String)
Public Property Technical As Dictionary(Of String, String)
Public Sub New(ByVal strID As String, ByVal lTechnical As Dictionary(Of String, String), ByVal lIndex As Dictionary(Of String, String), ByVal lChildren As Dictionary(Of String, String))
Me.ID = strID
'Me.Technical = New Dictionary(Of String, String)
'Me.Index = New Dictionary(Of String, String)
'Me.Children = New Dictionary(Of String, String)
Me.Technical = lTechnical
Me.Index = lIndex
Me.Children = lChildren
End Sub
End Class
I Hear, I Forget
I See, I Remember
I Do, I Understand
Ronald McDonald