B4J Question put xList in xList...

Lego Jérôme

Member
Licensed User
Hi,

In my code i want to create : x number of list and put in x number of list


My gui : Interface graphique.png
User can add X tabpane in X tabpane....

And i try this code without success..
B4X:
Sub CreateListOfLbl
    Dim l As List
    l.Initialize
    'AllLblGeneralChapitre contient des listes pour chaque matiere, ces listes contiennes les lbl des matieres
    For i=1 To listMatiere.Size-1'For x "matiere" i want to put a list with array of string in list: "AllLblGeneralChapitre"  example of array : "AA,AB,AC,AD,..."
        l=Structure.BlocChapitre(i)'structure.blocChapitre return a list
        For x=0 To l.Get(0)-1 'in l.get(0) they have the number of string in array : if l.get(0)=1  array = "AA" | if l.get(0)=3  array = "AA,AB,AC"
            TakeLbl(0,Lx) 'TakeLbl, add string "AA" or other if AA is already selected...  in list Lx           
        Next
        AllLblGeneralChapitre.Add(Lx)'Now i put my list in my list, at this step i think is good
        Lx.Clear 'but now i need to clear Lx list for the next loop, when i do that, AllGeneralChapitre.get(0) return nothing because i clear the list...       
    Next
    
    
    LogList(AllLblGeneralChapitre.Get(0))
    
End Sub
 

stevel05

Expert
Licensed User
Longtime User
You don't show where Lx is defined. Is it a Global variable?

When you add LX to the list is just adds a pointer to the list, which is why it is cleared when you call Lx.Clear.

Instead of Lx.Clear, you need to Dim a new object.
B4X:
Dim Lx As List
Lx.Initialize

It will still remain a global variable (if it was already)
 
Upvote 0

Lego Jérôme

Member
Licensed User
You don't show where Lx is defined. Is it a Global variable?

When you add LX to the list is just adds a pointer to the list, which is why it is cleared when you call Lx.Clear.

Instead of Lx.Clear, you need to Dim a new object.
B4X:
Dim Lx As List
Lx.Initialize


yes Lx is a global variable
And yes Lx is cleared but if i can do that, why can I dim a new list with a other name of any loop of my do While loop ?

I don't know how much loop will be achieved...
 
Upvote 0

Lego Jérôme

Member
Licensed User
I actually use the code that you passed me,
B4X:
Sub CreateListOfLbl
    Dim l As List
    l.Initialize
    'AllLblGeneralChapitre contient des listes pour chaque matiere, ces listes contiennes les lbl des matieres
    For i=1 To listMatiere.Size-1'For x "matiere" i want to put a list with array of string in list: "AllLblGeneralChapitre"  example of array : "AA,AB,AC,AD,..."
        Dim Lx As List
        Lx.Initialize
        l=Structure.BlocChapitre(i)'structure.blocChapitre return a list
        For x=0 To l.Get(0)-1 'in l.get(0) they have the number of string in array : if l.get(0)=1  array = "AA" | if l.get(0)=3  array = "AA,AB,AC"
            Lx.Add(TakeLbl(0)) 'TakeLbl, add string "AA" or other if AA is already selected...  in list Lx      
        Next
        AllLblGeneralChapitre.Add(Lx)'Now i put my list in my list, at this step i think is good
    Next
 
    For i=0 To AllLblGeneralChapitre.Size-1
        Log("liste chapitre "&i&" :")
        LogList(AllLblGeneralChapitre.Get(0))
    Next
 
End Sub

i have delete my :
B4X:
Lx.Clear

But now "AllLblGeneralChapitre" contains x * the last list "Lx" create in For-Next...
I do not understand how it's possible to create variables list all different, for each loop.
 
Upvote 0

stevel05

Expert
Licensed User
Longtime User
The new Dim needs to be where you had the clear statement, so once you added all the items, it will create a new list

B4X:
Sub CreateListOfLbl
    Dim l As List
    l.Initialize
    'AllLblGeneralChapitre contient des listes pour chaque matiere, ces listes contiennes les lbl des matieres
    For i=1 To listMatiere.Size-1'For x "matiere" i want to put a list with array of string in list: "AllLblGeneralChapitre"  example of array : "AA,AB,AC,AD,..."
         l=Structure.BlocChapitre(i)'structure.blocChapitre return a list
        For x=0 To l.Get(0)-1 'in l.get(0) they have the number of string in array : if l.get(0)=1  array = "AA" | if l.get(0)=3  array = "AA,AB,AC"
            Lx.Add(TakeLbl(0)) 'TakeLbl, add string "AA" or other if AA is already selected...  in list Lx 
        Next
     
    Next
 
        AllLblGeneralChapitre.Add(Lx)'Now i put my list in my list, at this step i think is good
        Dim Lx As List
        Lx.Initialize
 
    For i=0 To AllLblGeneralChapitre.Size-1
        Log("liste chapitre "&i&" :")
        LogList(AllLblGeneralChapitre.Get(0))
    Next
 
End Sub

Edit: In fact I think you probably need to move the add outside of the loops if you want all items in one list.
 
Last edited:
Upvote 0

Lego Jérôme

Member
Licensed User
I'm stupid it's been a while that my sub is just... (with your help) :)
That the problem did not come from my list but my log

my mistake
B4X:
    For i=0 To AllLblGeneralChapitre.Size-1
        Log("liste chapitre "&i&" :")
        LogList(AllLblGeneralChapitre.Get(0))
    Next

Now, it's fine !
B4X:
    For i=0 To AllLblGeneralChapitre.Size-1
        Log("liste chapitre "&i&" :")
        LogList(AllLblGeneralChapitre.Get(i))
    Next

Sans titre.png And my log that I've been waiting for a while

Thank you so much stevel05 !
 
Upvote 0
Top