Android Question Fill an array

interlnk

Member
Licensed User
I try an array in B4a, but there is an error. The code could be similar to this:

Dim i As Int
Dim text As String
Dim arr() As String

text = "hola"

For i = 1 To 20
arr(i) = text & i
Next

What's wrong?
 

Star-Dust

Expert
Licensed User
Longtime User
B4X:
Dim i As Int
Dim text As String
Dim arr(20) As String ' define a size

text = "hola"

For i = 0 To 19
arr(i) = text & (i + 1)
Next
 
Upvote 0

Cableguy

Expert
Licensed User
Longtime User
Arrays index start at ZERO so an array that holds 20 items will be indexed from 0 to 19.
In code we tend to use For X = 0 to Array.Lenght -1 where length hold the number of items in the array
 
Upvote 0
Top