Android Question Arrays question - VB to B4A

kepler

Active Member
Licensed User
Good afternoon,

I'm having some problems in declaring nested arrays in B4A.
In VB6 (and VB .NET) we can declare, for instance:

B4X:
Dim nbTerms()() As Integer = ((193, 26, 13), (183, 29, 14), (170, 20, 11))
But how do we declare this type of array in B4A?

Kind regards,

Kepler
 

kepler

Active Member
Licensed User
Hi Erel,

Yes, I was aware of that, thanks. I've read the Guide - it's very useful.
But couldn't we develop a method to treat the kind of nested arrays I spoke? Like a tool?
I'm thinking about it...:confused:

Kind regards,

Kepler
 

kepler

Active Member
Licensed User
The Array keyword only creates single dimension arrays. However with the code posted here you can create 2d arrays.

You can create arrays with as many dimensions as you like
Hi Erel - again

Just a question if I may: supose that we have the following code in C++ (a bit like VB .Net)

B4X:
int a[3][4] = {
{0, 1, 2, 3} ,
{4, 5, 6, 7} ,
{8, 9, 10, 11}
};
Can we declare it in B4A like:

B4X:
Dim a(3,4) as Int
a = (0,1,2,3,4,5,6,7,8,9,10,11)
Will it be interpreted correctly?

Kind regards,

Kepler
 
Last edited:

kepler

Active Member
Licensed User
Hi Don,

Well, the code snippet gives an error in B4A.
But...even so, it doesn't deal with all dynamic arrays.
Isn't there a way to automate this job? The code I placed doesn't work... :(

Kind regards,

Kepler
 

kepler

Active Member
Licensed User
Hi guys,

I was thinking in a solution... :confused:

What if we declare for:

B4X:
int a[3][4] = {
{0, 1, 2, 3} ,
{4, 5, 6, 7} ,
{8, 9, 10, 11}
};
the following statement in B4A:

B4X:
Dim a

a = Array(Array(0, 1, 2, 3), Array(4, 5, 6, 7), Array(8, 9, 10, 11))
?

Will it work?

Kind regards,

Kepler
 

Troberg

Well-Known Member
Licensed User
I can see a use for this. For example, a multidimensional array has the same number of items in every "row", while an array or arrays could have a different number if items in each sub-array.
 
Top