Array Issue....Help...

Cableguy

Expert
Licensed User
Longtime User
Working with arrays in B4Ppc was quite straight-foward, but not so easy in B4A...

I have This code:
B4X:
   Dim Table As String
   Table = File.ReadString(File.DirInternal,"ScoreTable.txt")
   Dim Scores() As String
   c = Table.IndexOf(Level)
   Msgbox(table,c)
   For i = 0 To 24
         d=Table.IndexOf(",")
         Msgbox(d,",")
         Scores(i) = Table.SubString2(c,d)
         Msgbox(scores(i),"Word")
'         c = Table.IndexOf2(",",c+1)
         Table = Table.SubString(d)
         c = c + 2
         Msgbox(table,"String")
         'Msgbox(Scores(i),c)   
   Next
What it should do? It should take the Table String read from a file, formated to be scv, and place each value into the array...and then erase the current value from the string, comma included...But it is not working, I keep getting an "OutOfBaounds" error...HELP

Msgbox are ther so I can keep track of what is beeing done by the loop...And it seems to be all good,except tha filling of the array..
 

Cableguy

Expert
Licensed User
Longtime User
Putting some more msgboxes has lead me to the brilliant conclusion that one of my indexes was of...
Now is the for next loop that won't loop-out when i=24...:BangHead:

PS....Other rookie mistake...Now going for the array filling...
 
Last edited:
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
Closed!!!!!
Final code:

B4X:
Dim Table As String
   Table = File.ReadString(File.DirInternal,"ScoreTable.txt")
   Dim Scores(25) As String
   c = Table.IndexOf(Level)
   Table = Table.SubString(c)
   For i = 0 To 24
         d=Table.IndexOf(",")
         c = 0
         Scores(i) = Table.SubString2(c,d)
         Table = Table.SubString(d + 1)
   Next
This takes a string from a file, CSV formated with an extra "," ate the end value, And loads series of 25 values into an array, from that string, from the first word that matches "Level"

Hope this helps anyone
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…