D DawningTruth Active Member Licensed User Mar 6, 2019 #1 I am running the code analogous to the following: Code: Copy GroupOfElements As List For n = 0 To 4 Element.Initialize Element.ID = n Element.TextField = "Element " + n GroupOfElements.Add(Element) Next The idea is to add a couple of elements to a list. The code adds the elements as reference. This means that every element is identical and you get a list filled with: GroupOfElements [0] Element.ID = 4; Element.TextField = "Element 4" [1] Element.ID = 4; Element.TextField = "Element 4" [2] Element.ID = 4; Element.TextField = "Element 4" [3] Element.ID = 4; Element.TextField = "Element 4" [4] Element.ID = 4; Element.TextField = "Element 4" Is there any way I can add the elements by value instead of reference?
I am running the code analogous to the following: Code: Copy GroupOfElements As List For n = 0 To 4 Element.Initialize Element.ID = n Element.TextField = "Element " + n GroupOfElements.Add(Element) Next The idea is to add a couple of elements to a list. The code adds the elements as reference. This means that every element is identical and you get a list filled with: GroupOfElements [0] Element.ID = 4; Element.TextField = "Element 4" [1] Element.ID = 4; Element.TextField = "Element 4" [2] Element.ID = 4; Element.TextField = "Element 4" [3] Element.ID = 4; Element.TextField = "Element 4" [4] Element.ID = 4; Element.TextField = "Element 4" Is there any way I can add the elements by value instead of reference?
Star-Dust Expert Licensed User Longtime User Mar 6, 2019 #2 To avoid addressing the same variable does not enough initialize but you have to DIM it every time Code: Copy GroupOfElements As List For n = 0 To 4 Dim Element as MyTYpe Element.Initialize Element.ID = n Element.TextField = "Element " + n GroupOfElements.Add(Element) Next Last edited: Mar 6, 2019 Upvote 0
To avoid addressing the same variable does not enough initialize but you have to DIM it every time Code: Copy GroupOfElements As List For n = 0 To 4 Dim Element as MyTYpe Element.Initialize Element.ID = n Element.TextField = "Element " + n GroupOfElements.Add(Element) Next
D DawningTruth Active Member Licensed User Mar 6, 2019 #3 Star-Dust said: To avoid addressing the same variabiel does not enough initialize but you have to DIM it every time Code: Copy GroupOfElements As List For n = 0 To 4 Dim Element as MyTYpe Element.Initialize Element.ID = n Element.TextField = "Element " + n GroupOfElements.Add(Element) Next Click to expand... Thx that sorted it Upvote 0
Star-Dust said: To avoid addressing the same variabiel does not enough initialize but you have to DIM it every time Code: Copy GroupOfElements As List For n = 0 To 4 Dim Element as MyTYpe Element.Initialize Element.ID = n Element.TextField = "Element " + n GroupOfElements.Add(Element) Next Click to expand... Thx that sorted it