Re: can .range return a 1D array?



Bruce Bowler wrote:

Consider the example of implementing an algorithm that "works best" with a 1D array. Consider the case where sometimes you want to call that code with row (or portion of a row) worth of data and the SAME code with a column (or portion there of) worth of data. In 1 case the subscripts are (I,1), in the other they're (1,I). Yes, I know I could implement it with 2 loops going from lbound(x,1) to ubound(x,1) and lbound(x,2) and ubound
(x,2). Now suppose I (or someone else who borrowed the code) wants to call it with an array created via the ARRAY function. Yep, could code that too, but the code is *MUCH* simpler to understand (and less likely to contain errors) if it treats the input as a vector rather than an array.

I know moan and groan, it's not going to change. I'll just live with it.


Perhaps the following might be useful.

If arr is a single column 2-D array, then

arr = Application.Transpose(arr) will convert it to a 1-D array.

And if arr is a single row 2-D array, then

arr = Application.Index(arr,1,0) will convert it to a 1-D array.

And if the functions in the freely downloadable file at http://home.pacbell.net/beban are available to your workbook, then

arr = OneD(arr) will convert either a single row 2-D array or a single column 2-D array to a 1-D array, and will leave a 1-D array as a 1-D array.

Alan Beban
.



Relevant Pages

  • Re: Evaluating unary *
    ... 'arr' exists, ... value can be used with the same syntax as would be used to access a 2D array of the kind you're referring to, but that 2D array is just a different way of looking as the same object that was already created by the definition of 'arr'. ... to me, it makes sense to return a pointer to the first value of an array, but to return the address of the pointer to the first value of an array, is not directly possible as such. ... lea eax, ...
    (comp.std.c)
  • Re: Evaluating unary *
    ... value can be used with the same syntax as would be used to access a 2D array of the kind you're referring to, but that 2D array is just a different way of looking as the same object that was already created by the definition of 'arr'. ... the expression &arr requires no special handling beyond insertion of the appropriate address into a suitable register. ... to me, it makes sense to return a pointer to the first value of an array, but to return the address of the pointer to the first value of an array, is not directly possible as such. ... It does create a pointer value which points at arr itself, and treats the entirety of arr as the first element in an array containing exactly one element of type int. ...
    (comp.std.c)
  • Re: multi dimensional arrays as one dimension array
    ... Are you of the opinion that one or both of memcpy(p, arr, sizeof arr) ... way of converting a two-dimensional array into a one-dimensional ... &arr) is supposed to be pointer constrained legally to range over ... arrays of character type and other objects treated as arrays ...
    (comp.lang.c)
  • Re: can .range return a 1D array?
    ... Alan Beban wrote: ... call it with an array created via the ARRAY function. ... If arr is a single column 2-D array, ... And if arr is a single row 2-D array, ...
    (microsoft.public.excel.programming)
  • Re: can .range return a 1D array?
    ... LBound of arrays that are declared like this: ... Dim ptr As Long ... ' Variant parameter that has received the array ... ' Sets Ary's LBound to NewBound, ...
    (microsoft.public.excel.programming)

Loading