Error when loading a list from LoadCSV

splatt

Active Member
Licensed User
Longtime User
Code: Copy
Sub btnFiles_Click
    Dim su As StringUtils
    Dim Table As List
    Dim fName, pegName As String
    Dim fd As FileDialog
    Dim fSize As Int
 
    table.Initialize
    fd.FastScroll = True
    fd.FilePath =File.DirRootExternal&"/Android/data/encoded.b4a/files/encoded" 
    fd.FileFilter = ".cat" 
    If fd.Show("Select Catalog File", "Yes", "No", "", Null) =DialogResponse.POSITIVE Then 
        Table = su.LoadCSV(fd.FilePath, fd.ChosenName, ",")
        Log(fd.FilePath&" , "&fd.ChosenName)
        For i = 0 To table.Size - 1
           pegName = table.Get(i)
           Log(pegName)
       Next
    End If
End Sub

I'm trying to read a file that contains imagefile names:
"1.gif","2.gif","3.gif","4.gif","5.gif","6.gif","7.gif","8.gif"

I get an error at this line: Table = su.LoadCSV(fd.FilePath, fd.ChosenName, ",")

java.lang.StringIndexOutOfBoundsException

What am I doing wrong?
 
Saved the text file as UTF-8.

Now the file is loaded without errors.

Code: Copy
For i = 0 To table.Size - 1
   pegName = table.Get(i)
   Log(table.Size&" - "&pegName)
Next

When I execute this code, all I get is:
1 - [Ljava.lang.String;@481fd7d8
 
Upvote 0
Each row in the table List is made of an array.
To get the cells you should do something like:
Code: Copy
For i = 0 To table.Size - 1
 Dim cells() As String
 cells = table.get(i)
 for c = 0 To cells.Length - 1
   Log(cells(c))
 Next
Next

Thanks Erel, that has worked. Bizarely, the first item is still wrapped in double quotes, the rest have been stripped off.
 
Upvote 0
coma separated CSV file

Sorry,
I'm quite new on B4A.
I'm still having the same problem even if I save it in Unicode.
If I change the the SeparatorChar from "," to ";" it works.
But I do not want to use it because I need to include more than one eMail address separated by semicolon.
Thank you,
Carlo

Saved the text file as UTF-8.

Now the file is loaded without errors.
 
Upvote 0
Ok,
now it works even with comma!
After the Unicode saving the text file was corrupted
(some hidden characters at the beginning, probably due to mishandling or some editors I tried!).


Sorry,
I'm quite new on B4A.
I'm still having the same problem even if I save it in Unicode.
If I change the the SeparatorChar from "," to ";" it works.
But I do not want to use it because I need to include more than one eMail address separated by semicolon.
Thank you,
Carlo
 
Upvote 0
Back
Top