Android Question Array and End of file

Giusy

Active Member
Licensed User
Hi,
I need to read a file (txt) and store the values in an array.

1) How do I indicate the size of the array if I do not know the number of records?

2) If I use:

B4X:
    Do While True
    If EOF then exit  '????
    loop

What is the correct instruction that I have to insert in the second line?

Thank you
 

Computersmith64

Well-Known Member
Licensed User
Longtime User
You could use a list of maps. Something like (off the top of my head, not tested, so might not be 100% correct):

B4X:
Private lstRecs as List
Private recMap as Map

lstRecs.Initialize
'Add Items to the list
 For Each Row() As String In su.LoadCSV (File.DirAssets, "myfile.txt",",")
        recMap.Initialize
        recMap.Put(Row(0), Row(1))
        lstRecs.Add(recMap)
    Next

'Get items from the list
For i = 0 to lstRecs.Size - 1
    Private m as Map = lstRecs.Get(i)
    Log(m.GetKeyAt(0))
    Log(m.GetValueAt(0))
Next

- Colin.
 
Upvote 0
Top