Variable use

BPak

Active Member
Licensed User
Longtime User
I looked through the Variables & Objects in Basic4android documents

B4X:
Dim arr(3) As Int 'This call is redundant in this case.
Dim List1 As List
List1.Initialize
For i = 1 To 5 
Dim arr(3) As Int 
arr(0) = i * 2 
arr(1) = i * 2 
arr(2) = i * 2 
List1.Add(arr) 'Add the whole array as a single item
Next

arr = List1.Get(0) 'get the first item from the list
Log(arr(0)) 'Will print 2

The code line:
arr = List1.Get(0) 'get the first item from the list
does not use an index for arr.

Is arr still the array variable? If so which index is receiving the data?
 
Last edited:

derez

Expert
Licensed User
Longtime User
After the code runs:
List1 has five elements - the array arr, which has three elements, values multiples of 2.

You read the first element in list1 and get the first array arr (not the first element of it !)
You log the first element of that array arr and get 2 , ( 1 * 2).

the line
B4X:
arr = List1.Get(0)
get the first item from the list and it is the complete array arr, not the first element of the array. !
 
Last edited:
Upvote 0

BPak

Active Member
Licensed User
Longtime User
Thanks Derez.

Understand now. Reading the first Item of the LIST returns :- arr(0), arr(1), arr(2) into the arr Variable.

:sign0104:
 
Upvote 0
Top