kepler Active Member Licensed User Longtime User Mar 18, 2015 #1 Good afternoon, I'm having some problems in declaring nested arrays in B4A. In VB6 (and VB .NET) we can declare, for instance: Code: Copy 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
Good afternoon, I'm having some problems in declaring nested arrays in B4A. In VB6 (and VB .NET) we can declare, for instance: Code: Copy 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
Erel B4X founder Staff member Licensed User Longtime User Mar 18, 2015 #2 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: Code: Copy Dim m(10,10,20,30,40) As Int Upvote 0
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: Code: Copy Dim m(10,10,20,30,40) As Int
kepler Active Member Licensed User Longtime User Mar 18, 2015 #3 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... Kind regards, Kepler Upvote 0
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... Kind regards, Kepler
kepler Active Member Licensed User Longtime User Mar 18, 2015 #4 Erel said: 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 Click to expand... Hi Erel - again Just a question if I may: supose that we have the following code in C++ (a bit like VB .Net) Code: Copy int a[3][4] = { {0, 1, 2, 3} , {4, 5, 6, 7} , {8, 9, 10, 11} }; Can we declare it in B4A like: Code: Copy 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: Mar 19, 2015 Upvote 0
Erel said: 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 Click to expand... Hi Erel - again Just a question if I may: supose that we have the following code in C++ (a bit like VB .Net) Code: Copy int a[3][4] = { {0, 1, 2, 3} , {4, 5, 6, 7} , {8, 9, 10, 11} }; Can we declare it in B4A like: Code: Copy 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
kepler Active Member Licensed User Longtime User Mar 19, 2015 #6 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 Upvote 0
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 Longtime User Mar 19, 2015 #7 Hi guys, I was thinking in a solution... What if we declare for: Code: Copy int a[3][4] = { {0, 1, 2, 3} , {4, 5, 6, 7} , {8, 9, 10, 11} }; the following statement in B4A: Code: Copy 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 Upvote 0
Hi guys, I was thinking in a solution... What if we declare for: Code: Copy int a[3][4] = { {0, 1, 2, 3} , {4, 5, 6, 7} , {8, 9, 10, 11} }; the following statement in B4A: Code: Copy 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
Erel B4X founder Staff member Licensed User Longtime User Mar 20, 2015 #8 It will create an array of objects where each item is an array. You will not be able to access the items with a(1,2). Upvote 0
It will create an array of objects where each item is an array. You will not be able to access the items with a(1,2).
T Troberg Well-Known Member Licensed User Longtime User Mar 20, 2015 #9 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. Upvote 0
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.