+ Reply to Thread
Results 1 to 8 of 8

is an array of arrays awkward or desirable programming practice?

  1. #1
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,829

    is an array of arrays awkward or desirable programming practice?

    I have undertaken a project to write a UDF that will take a parametric array as an argument. The thing that is looking awkward to me is that each element of the parametric array will be an array/range itself. Recognizing that a series of polynomials is an imperfect example, here is how it looks for a series of polynomials.
    Please Login or Register  to view this content.
    I'm sure I could process polys() into a 2D array before moving on to the main processing loops, but is such a step necessary? Do I just need to bite the bullet and become more comfortable with this "array of arrays" notation? Or do "real" programmers prefer not to work with this array of arrays structure?
    Does anything change if I add that in my real project, each element of polys is a 2D range? Which is really worse:
    a 3D array polys(i,j,k)
    a paramarray of 2D arrays polys(i)(j,k)

    I realize that this kind of thing may not have a solid answer, but I would appreciate some feedback from more experienced programmers.
    Attached Files Attached Files
    Last edited by MrShorty; 09-24-2015 at 12:55 PM. Reason: add attachment
    Quote Originally Posted by shg
    Mathematics is the native language of the natural world. Just trying to become literate.

  2. #2
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: is an array of arrays awkward or desirable programming practice?

    As you suggest, it depends. Jagged arrays can be quite useful (ie each Sub array may not have the same dimensions). Even when the sub arrays are the same size it can be handy to have an array of arrays - especially if you plan to reorder the first dimension.

    Mostly I'd say if your function is going to receive an array of arrays, you may as well process that way rather than going to the trouble of converting to one n-dimensional array.

    Hope that's of some use.
    Remember what the dormouse said
    Feed your head

  3. #3
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: is an array of arrays awkward or desirable programming practice?

    There's nothing wrong with jagged arrays (arrays of arrays), in fact 2 dimensional arrays are pretty rare as a programming concept.

    The only reason they're so prevalent in VBA is because they're easy to work with in the Excel environment, you can use worksheet functions on them and they map to rows and columns on worksheets so they're easy for reading and writing.

    If jagged arrays make more sense then go for that, if a 2 dimensional approach makes more sense then use that - horses for courses.

  4. #4
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,829

    Re: is an array of arrays awkward or desirable programming practice?

    Thanks for the responses.

    An Additional comment. While my example is hard coded for 4 polys, the real function would have anywhere from 1 to 7 or so polys. The advantage of using a parametric array is that I do not need a list of 7 optional arguments for each poly. I can have the one parametric array argument, and the number of ranges included in that parametric array tells the function how many polys are being calculated. Perhaps this expresses the question differently, when working with arrays/ranges, is it preferable to use a list of optional arguments or a parametric array?

    Perhaps the other idea, brought on by this "jagged array" concept, is that sometimes each poly will be a different order (so to speak). So poly 1 may be a cubic, like shown, but poly 2 is a quartic, and poly 3 is linear, and poly 4 is a single constant, or whatever. This could add extra advantage to the use of a jagged array.

    It looks like this "array of arrays" is a useful concept that other programmers use, so I guess I will bite the bullet and make myself comfortable using it.

  5. #5
    Forum Expert Doc.AElstein's Avatar
    Join Date
    05-23-2014
    Location
    '_- Germany >Outside Building things.... Mostly
    MS-Off Ver
    Office 2003 2007 2010 PC but Not mac. XP and Vista mostly, sometimes Win 7
    Posts
    3,618

    Re: is an array of arrays awkward or desirable programming practice?

    Hi Shorty,
    Quote Originally Posted by MrShorty View Post
    ........
    It looks like this "array of arrays" is a useful concept that other programmers use,....
    _ I have always been a great fan of Arrays, keeping as much “ away from the spreadsheet “ , capturing and pasting to the spreadsheet in “One Liners” etc.
    _ I sort of fell into thinking in the two dimensional “row” , “column” way of thinking about them.
    _ But then I hit on the further possibilities in a few Threads..
    http://www.mrexcel.com/forum/excel-q...d-array-2.html
    of, in particular the idea of a 1D Array of 2D Arrays. I have found that took my efficiency of Arrays that one step further, especially when sorting stuff from multiple sheets,
    _ every element in the “ Outer” 1 D Array is a sheet , and the “grid” of a sheet is each of the “Inner” 2 D Arrays.
    _ A simple and obvious concept, but it seems to really “fit” well sometimes..

    Quote Originally Posted by MrShorty View Post
    ........... so I guess I will bite the bullet and make myself comfortable using it.
    _ I always have a second Monitor with a big Watch window open in with all my Important Arrays in it when I develop Codes using Arrays
    http://www.mrexcel.com/forum/lounge-...aneously.html?
    _ I am not sure If i could live without that, yet..
    Alan
    '_- Google first, like this _ site:ExcelForum.com Gamut
    Use Code Tags: Highlight code; click on the # icon above,
    Post screenshots COPYABLE to a Spredsheet; NOT IMAGES PLEASE
    http://www.excelforum.com/the-water-...ml#post4109080
    https://app.box.com/s/gjpa8mk8ko4vkwcke3ig2w8z2wkfvrtv
    http://excelmatters.com/excel-forums/ ( Scrolll down to bottom )

  6. #6
    Forum Guru
    Join Date
    04-13-2005
    Location
    North America
    MS-Off Ver
    2002/XP and 2007
    Posts
    15,829

    Re: is an array of arrays awkward or desirable programming practice?

    Doc.AElstein: Your example of a 1D array of "sheets", where each "sheet" has a 2D array is a pretty good parallel to what I see happening in this calculation. Rather than "sheets", I see "blocks" of cells on the same sheet. In many ways, I would have defaulted to a 3D array, except the parametric array creates an array of "range" objects. Now that I can see that others use this kind of data structure to good effect, I will try to learn and use it as well.

  7. #7
    Forum Expert Doc.AElstein's Avatar
    Join Date
    05-23-2014
    Location
    '_- Germany >Outside Building things.... Mostly
    MS-Off Ver
    Office 2003 2007 2010 PC but Not mac. XP and Vista mostly, sometimes Win 7
    Posts
    3,618

    Re: is an array of arrays awkward or desirable programming practice?

    Hi
    Quote Originally Posted by MrShorty View Post
    .. Now that I can see that others use this kind of data structure to good effect, I will try to learn and use it as well.
    -- and i see you use XP. I use mostly XP and Vista, and mostly XL2007. I swear by the 2 Monitor bit - That works very well in those Operating systems. I use a Big Old Telly as the second Monitor. I strongly recommend that to get a big Watch Window to look inside your Arrays as they are being filled. ( As well of course of being able to get both the spreadsheet and the VB Development Window clearly visible at the same time. Although as i capture in and paste out in one go typically, i rarely need to look at the spreadsheet )
    Alan

  8. #8
    Registered User
    Join Date
    08-18-2015
    Location
    Utrecht, Netherlands
    MS-Off Ver
    2010
    Posts
    69

    Re: is an array of arrays awkward or desirable programming practice?

    wrong screen
    Last edited by CostCare; 10-08-2015 at 04:50 AM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. What's the best practice for determining unique values in multiple arrays?
    By dmasters4919 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 04-15-2015, 05:38 PM
  2. [SOLVED] How to apply header to desirable row
    By pabloponza in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 02-01-2014, 01:51 AM
  3. Replies: 6
    Last Post: 09-25-2013, 10:08 PM
  4. [SOLVED] New to arrays-how do I build new array while filtering first array?
    By mc84excel in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-03-2013, 05:59 AM
  5. [SOLVED] Awkward last used row problem
    By ScabbyDog in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-05-2013, 03:03 PM
  6. Summarising awkward extract
    By Sibrulotte in forum Excel General
    Replies: 0
    Last Post: 06-22-2011, 09:59 AM
  7. Array Size & Dimensions Best Practice
    By pipsturbo in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 01-26-2011, 11:34 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1