B4J Question Extracting a List from a List

Paul_

Member
Licensed User
Hi All,

I have a small issue of how to extract lists from a master list?

Example data:

list1="1","2","3","4"
list2="10","20","30","40"
list3="100","200","300","400"

I can combine three lists into a master list and save/write as here;

MasterList.Add(list1)
MasterList.Add(list2)
MasterList.Add(list3)

File.WriteList(File.DirApp, "MasterList.txt", MasterList)

Reading back:

MasterList=File.ReadList(File.DirApp, "MasterList.txt")

I have tried several methods but I cannot solve how to extract each item from the MasterList as a list and reload the lists list1, list2, list3 ?

list1.Add(MasterList.Get(0)) will just load the whole list as a single item in list1.

My intention is to combine some lists to send as a single packet stream, I know could send them separately but if I can solve how to convert a list of lists back into individual lists it would be very useful.

Thanks for any help.
 

Erel

Administrator
Staff member
Licensed User
Please use [code]code here...[/code] tags when posting code.

Don't use File.ReadList.
B4X:
Dim list1 As List = Array("1", "2")
Dim list2 As List = Array("10", "20")
Dim list3 As List = Array("100", "200")
Dim master As List = Array(list1, list2, list3)
Dim ser As B4XSerializator
File.WriteBytes(File.DirApp, "Master.dat", ser.ConvertObjectToBytes(master))

Dim NewMaster As List = ser.ConvertBytesToObject(File.ReadBytes(File.DirApp, "Master.dat"))
Dim NewList1 As List = NewMaster.Get(0)
Note that writing to File.DirApp is a mistake if you plan to create an installer to your app.
 

Paul_

Member
Licensed User
Excellent! Thank you Erel.

That method is very useful and something I would never have figured out. The B4X community is fantastic.
 
Top