A avnersh Member Licensed User Longtime User Aug 2, 2011 #1 Hello all I'm trying to use the list object by adding to the list an item than define by type Actually once I added new item ,all the previous items in list become the some as the new inserted item. This is my simple code that demonstrate the problem Am i using the list in the right way? Thank avner shmuel Sub Process_Globals Type equation_group(name As String,pictur_file As String) Dim list1 As List Dim group_test As equation_group Dim i As Int End Sub Sub Activity_Create(FirstTime As Boolean) group_test.Initialize list1.Initialize For i= 1 To 10 group_test.name="n"& i group_test.pictur_file="p"& i list1.Add(group_test) Next End Sub Last edited: Aug 2, 2011
Hello all I'm trying to use the list object by adding to the list an item than define by type Actually once I added new item ,all the previous items in list become the some as the new inserted item. This is my simple code that demonstrate the problem Am i using the list in the right way? Thank avner shmuel Sub Process_Globals Type equation_group(name As String,pictur_file As String) Dim list1 As List Dim group_test As equation_group Dim i As Int End Sub Sub Activity_Create(FirstTime As Boolean) group_test.Initialize list1.Initialize For i= 1 To 10 group_test.name="n"& i group_test.pictur_file="p"& i list1.Add(group_test) Next End Sub
K Kamac Active Member Licensed User Longtime User Aug 2, 2011 #2 For v= 1 To 10 group_test.name="n"& i group_test.pictur_file="p"& i list1.Add(group_test) Next Click to expand... Um... That makes no sense, because you do: For v = 1 And you try to include "i". list1.Add(group_test) Click to expand... Looks strange also. You could use: list1.Add(group_test.name & " " & group_test.pictur_file) Click to expand... I'm unsure if list1.Add(group_test) is right, i'd change it. Upvote 0
For v= 1 To 10 group_test.name="n"& i group_test.pictur_file="p"& i list1.Add(group_test) Next Click to expand... Um... That makes no sense, because you do: For v = 1 And you try to include "i". list1.Add(group_test) Click to expand... Looks strange also. You could use: list1.Add(group_test.name & " " & group_test.pictur_file) Click to expand... I'm unsure if list1.Add(group_test) is right, i'd change it.
A avnersh Member Licensed User Longtime User Aug 2, 2011 #3 Hi KAMAC First of all thank you ... The V instead of i in the for next loop is my typing mistake :signOops: Yet I'm not understanding way the list cannot accept an structure item in the manual the item is note define as a string but as an object Add (item As Object) Regards Avner Upvote 0
Hi KAMAC First of all thank you ... The V instead of i in the for next loop is my typing mistake :signOops: Yet I'm not understanding way the list cannot accept an structure item in the manual the item is note define as a string but as an object Add (item As Object) Regards Avner
K Kamac Active Member Licensed User Longtime User Aug 2, 2011 #4 Add (item As Object) Click to expand... Indeed, as object, but imagine what could a type contain? String could contain "daf" Integer could contain 5 List can contain: 4 6 8 "Lol" Try making a label and use: label1.Text = group_test We'll see what will it contain. Upvote 0
Add (item As Object) Click to expand... Indeed, as object, but imagine what could a type contain? String could contain "daf" Integer could contain 5 List can contain: 4 6 8 "Lol" Try making a label and use: label1.Text = group_test We'll see what will it contain.
agraham Expert Licensed User Longtime User Aug 2, 2011 #5 Indeed, as object, but imagine what could a type contain? Click to expand... If you can't post something relevant to the problem please don't post at all and stop cluttering the forum. all the previous items in list become the some as the new inserted item. Click to expand... This is a very common mistake. You need to Dim a new type inside the loop to get a new instance otherwise you are using the same instance of your type all the time. Read about it here in the first section "Types". Upvote 0
Indeed, as object, but imagine what could a type contain? Click to expand... If you can't post something relevant to the problem please don't post at all and stop cluttering the forum. all the previous items in list become the some as the new inserted item. Click to expand... This is a very common mistake. You need to Dim a new type inside the loop to get a new instance otherwise you are using the same instance of your type all the time. Read about it here in the first section "Types".
klaus Expert Licensed User Longtime User Aug 2, 2011 #6 You need to Dim the variable group_test in the For / Next loop. Code: Copy [COLOR=black]For i= 1 To 10 [/COLOR] [COLOR=black][COLOR=#ff0000] Dim group_test As equation_group[/COLOR] group_test.name="n"& i group_test.pictur_file="p"& i list1.Add(group_test) Next [/COLOR] Otherwise, when adding the last entry, you change the variables but they are the same for each entry. Diming in the loop you have a new onr each iteration. Best regards. Upvote 0
You need to Dim the variable group_test in the For / Next loop. Code: Copy [COLOR=black]For i= 1 To 10 [/COLOR] [COLOR=black][COLOR=#ff0000] Dim group_test As equation_group[/COLOR] group_test.name="n"& i group_test.pictur_file="p"& i list1.Add(group_test) Next [/COLOR] Otherwise, when adding the last entry, you change the variables but they are the same for each entry. Diming in the loop you have a new onr each iteration. Best regards.
A avnersh Member Licensed User Longtime User Aug 2, 2011 #7 agraham and klaus, thank you very much. you saved my first B4A application. :sign0098: Best regards Avner shmuel Upvote 0
agraham and klaus, thank you very much. you saved my first B4A application. :sign0098: Best regards Avner shmuel