It is sometimes necessary to fill arrays with some known values.
The most straightforward method is:
For larger arrays this method is a little cumbersome.
A much cleaner solution is to use StrSplit.
StrSplit splits a string and returns an array.
First we declare the array in sub Globals as an empty array.
Later we load the data using StrSplit:
Make sure that you don't leave any extra spaces inside the string.
The most straightforward method is:
B4X:
array(0) = 2
array(1) = 3
...
A much cleaner solution is to use StrSplit.
StrSplit splits a string and returns an array.
First we declare the array in sub Globals as an empty array.
Later we load the data using StrSplit:
B4X:
Sub Globals
Dim data(0)
Dim names(0)
End Sub
Sub App_Start
data() = StrSplit("2,3,5,7,11,13,17,19,23" , ",")
names() = StrSplit("John,Robert,Mike,Barbara" , ",")
'Show all names
For i = 0 To ArrayLen(names())-1
Msgbox(names(i))
Next
End Sub
Make sure that you don't leave any extra spaces inside the string.