Set values in two-dimensional array

Pantelis

Member
Licensed User
Longtime User
Hi to all
Is it possible to set the values in two-dimension array in a module in multiple lines of code like this?

B4X:
Dim Matrix(4,4) as Int

Matrix = Array as Integer:
 1,  2,  3, 4,  5:
 6,  7,  8, 9,10:
11,12,13,14,15:
16,17,18,19,20:
21,22,23,24,25:
Thanks
 

PenguinHero

Member
Licensed User
Longtime User
Hi Pantelis,

I don't believe that is possible.
If you literally wanted sequential numeric values in your array then the following would do it.
Note that there are only 16 elements in your array declaration, not 25.
B4X:
Sub Activity_Create(FirstTime As Boolean)
   
   Dim Matrix(4,4) As Int
   Dim x, y, counter As Int
   
   counter = 0
   For x = 0 To 3
      For y = 0 To 3
        counter = counter + 1
        Matrix(x,y) = counter
      Next ' y
   Next ' x
   
End Sub
 
Upvote 0

Pantelis

Member
Licensed User
Longtime User
Thanks for your answer PenguinHero
Yes the elements of my array is 16 indeed.
The number values are not sequential.
So the only way is to set the value one by one like this? And if i have an array(50,50) i need 250 lines of code?

B4X:
Dim Matrix(4,4) as Int

Matrix(0,0)=10
Matrix(0,1)=8
Matrix(0,2)=25
Matrix(0,3)=2
Matrix(1,0)=5
etc
 
Upvote 0
Top