Android Question Arrays question - VB to B4A

Discussion in 'Android Questions' started by kepler, Mar 18, 2015.

  1. kepler

    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:

    Code:
    Dim nbTerms()() As Integer = ((1932613), (1832914), (1702011))
    But how do we declare this type of array in B4A?

    Kind regards,

    Kepler
     
  2. Erel

    Erel Administrator Staff 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:
    Code:
    Dim m(10,10,20,30,40As Int
     
    kepler likes this.
  3. 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
     
  4. kepler

    kepler Active Member Licensed User

    Hi Erel - again

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

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

    Code:
    Dim a(3,4as 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
  5. DonManfred

    DonManfred Expert Licensed User

  6. kepler

    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
     
  7. kepler

    kepler Active Member Licensed User

    Hi guys,

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

    What if we declare for:

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

    Code:
    Dim a

    a = 
    Array(Array(0123), Array(4567), Array(891011))
    ?

    Will it work?

    Kind regards,

    Kepler
     
  8. Erel

    Erel Administrator Staff Member Licensed User

    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).
     
  9. Troberg

    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.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice