iOS Question Random error: Out of bounds. Index=1347794462 Length=4

voxel

Member
Licensed User
Hello,
I want to do row data processing with importing a CSV file that has 4 columns. I have this random error on the For Each loop and the Get "Out of bounds. Index=1347794462 Length=4". What is strange, I always have this error in Release mode and occasionally works in B4i-Bridge mode.
Thanks for your help.


B4X:
            Dim su As StringUtils
            Dim list As List
            list.Initialize
            list=su.LoadCSV(File.DirLibrary, "api.csv",";")
            list.RemoveAt(0)
      
 
            For Each tempMap As Map In list
              
                libmajparametre = tempMap.Get(0)
                rqanaori = tempMap.Get(1)
                refqual  = tempMap.Get(2)
                limitequal = tempMap.Get(3)
 

Filippo

Expert
Licensed User
Longtime User
A possible solution on the fly.

B4X:
            For Each tempMap As Map In list
              
                if tempMap.size > 0 then libmajparametre = tempMap.Get(0)
                if tempMap.size > 1 then rqanaori = tempMap.Get(1)
                if tempMap.size > 2 then refqual  = tempMap.Get(2)
                if tempMap.size > 3 then limitequal = tempMap.Get(3)
 
Upvote 0

voxel

Member
Licensed User
Thank you for this idea but I have the same error on the first get "If tempMap.size > 0 Then libmajparametre = tempMap.Get(0)".
Is this a problem with the use of Map?
 
Last edited:
Upvote 0

voxel

Member
Licensed User
It depends on how your csv file looks like.
Post a few lines of the file here.

An exemple with few lines of the file "api.csv" (with head) :

"libelle_parametre";"resultat_alphanumerique";"limite_qualite_parametre";"reference_qualite_parametre"
"Chlore total";"0,92";"";""
"pH";"7,6";"";">=6,5 et <=9 unité pH"
"Chlore libre";"0,91";"";""
"Bact. aér. revivifiables à 36°-44h";"<1";"";""
"Perchlorate";"7,5";"";""
"Ammonium (en NH4)";"<0,050";"";"<=0,1 mg/L"
 
Upvote 0

Filippo

Expert
Licensed User
Longtime User
Look at this example of Erel.
 
Upvote 0

voxel

Member
Licensed User
Thank, it's OK with this code

B4X:
    Dim su As StringUtils
            Dim list As List
            list.Initialize
            list=su.LoadCSV(File.DirLibrary, "api.csv",";")
            list.RemoveAt(0)
    
            Dim row() As String
        
            For i=0 To list.Size-1
                
                row = list.Get(i)
            
                libmajparametre = row(0)
                rqanaori = row(1)
                refqual  = row(2)
                limitequal = row(3)
 
Upvote 0
Top