Android Question List into Type

MarcoRome

Expert
Licensed User
Longtime User
Hi i have this code:

B4X:
Dim lst1 As List
lst1.Initialize
            lst1 = su.LoadCSV(directoryname, filename,";")

            Dim mtp As MyType
            mtp.Initialize
                For i = 0 To lst1.Size - 1
                    
                    Dim sColumn() As String
                    sColumn = lst1.Get(i)
                    Log(sColumn)
                    mtp = lst1.get(i)
                    Log(mtp.description_food)

                Next

Mytype is:
Type MyType(id_category_menu As Int , id_details As Int , description_food As String , description_extend As String ,price_small As Double, price_medium As Double, price_large As Double, picture_food As String, currency As String)

The File Excel that i load with LoadCSV is this:
excel.jpg


Now the problem is when i enter in For i see value Log(sColumn ) in correct mode:

[0=id_category_menu, 1=id_details, 2=description_food, 3=description_extend
, 4=price_small, 5=price_medium, 6=price_large
, 7=picture_food, 8=currency]

but when run line mtp=lst1.get(i) go in error.
Any idea ?
Thank you
Marco
 

DonManfred

Expert
Licensed User
Longtime User
but when run line mtp=lst1.get(i) go in error.
Any idea ?
You are trying to cast the type to a string array.
B4X:
Dim lst1 As List
lst1.Initialize
            lst1 = su.LoadCSV(directoryname, filename,";")

                For i = 0 To lst1.Size - 1
            Dim mtp As MyType
            mtp.Initialize
                    mtp = lst1.get(i)
                    Log(mtp.description_food)

                Next
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I just read your post right... Hmm, loading a csv into a string array will not help you to cast them to your custom type.
I think you need to match the string array

I think something like
B4X:
Dim lst1 As List
lst1.Initialize
            lst1 = su.LoadCSV(directoryname, filename,";")

                For i = 0 To lst1.Size - 1
                  
                    Dim sColumn() As String
                    sColumn = lst1.Get(i)
                    Log(sColumn)
                    Dim mtp As MyType
                    mtp.Initialize
                    mtp.id_category_menu = sColumn(0)
                    mtp.id_details = sColumn(1)
                    mtp.description_food = sColumn(2)
                    mtp.description_extend = sColumn(3)
                    mtp.price_small = sColumn(4)
                    mtp.price_medium = sColumn(5)
                    mtp.price_large = sColumn(6)
                    mtp.picture_food = sColumn(7)
                    mtp.currency = sColumn(8)                     Log(mtp.description_food)

                Next
 
Upvote 0

MarcoRome

Expert
Licensed User
Longtime User
I just read your post right... Hmm, loading a csv into a string array will not help you to cast them to your custom type.
I think you need to match the string array

I think something like
B4X:
Dim lst1 As List
lst1.Initialize
            lst1 = su.LoadCSV(directoryname, filename,";")

                For i = 0 To lst1.Size - 1
                 
                    Dim sColumn() As String
                    sColumn = lst1.Get(i)
                    Log(sColumn)
                    Dim mtp As MyType
                    mtp.Initialize
                    mtp.id_category_menu = sColumn(0)
                    mtp.id_details = sColumn(1)
                    mtp.description_food = sColumn(2)
                    mtp.description_extend = sColumn(3)
                    mtp.price_small = sColumn(4)
                    mtp.price_medium = sColumn(5)
                    mtp.price_large = sColumn(6)
                    mtp.picture_food = sColumn(7)
                    mtp.currency = sColumn(8)                     Log(mtp.description_food)

                Next
Right Don, right ;)
 
Upvote 0
Top