+ Reply to Thread
Results 1 to 9 of 9

write column vector of 2D array into 1 D array

  1. #1
    Registered User
    Join Date
    07-25-2008
    Location
    Tucson, AZ
    Posts
    90

    write column vector of 2D array into 1 D array

    I have a 2-D array dimensioned as

    Please Login or Register  to view this content.
    and filled with values

    I want to assign the column of entries into a 1D array which is dimensioned as

    Please Login or Register  to view this content.
    I want to do this in a single statement, without using a loop

    If I were writing in <real> language like MATLAB, I would just write

    Please Login or Register  to view this content.
    is there an equivalent in VBA?

  2. #2
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: write column vector of 2D array into 1 D array

    If BC_time were dimmed as a Variant, you could use

    Please Login or Register  to view this content.
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  3. #3
    Registered User
    Join Date
    07-25-2008
    Location
    Tucson, AZ
    Posts
    90

    Re: write column vector of 2D array into 1 D array

    interesting solution - works like a charm

    any idea why Excel would require Variant Dim? I thought the whole point of Option Explicit was to encourage you to declare specific data types?

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: write column vector of 2D array into 1 D array

    Because the Transpose function returns a Variant array, which can only be assigned to a Variant. It has nothing to do with Option Explicit.
    Entia non sunt multiplicanda sine necessitate

  5. #5
    Registered User
    Join Date
    07-25-2008
    Location
    Tucson, AZ
    Posts
    90

    Re: write column vector of 2D array into 1 D array

    then my next question is "why would Transpose, which should simply re-organize array entries, change their data type?" Assuming the user intended the input array to be type Double or whatever, why would the code force an output type of Variant?

  6. #6
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: write column vector of 2D array into 1 D array

    Just the facts on the ground, ma'am.

  7. #7
    Registered User
    Join Date
    07-25-2008
    Location
    Tucson, AZ
    Posts
    90

    Re: write column vector of 2D array into 1 D array

    definitely <interesting> learning the quirks of each programming language

    and maybe dangerous to ask "why?" LOL

  8. #8
    Forum Guru
    Join Date
    08-26-2007
    Location
    London
    Posts
    4,606

    Re: write column vector of 2D array into 1 D array

    I could tell you, but then shg would have to kill you. And then me.

  9. #9
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: write column vector of 2D array into 1 D array

    I imagine it's related to its heritage as a worksheet function, and for the fact that the implementation would be more complex to discern the variable type and return a like type.

    Even so, I accept it for Transpose, which could obviously return variable results. I'm less tolerant that it's true for matrix functions, which could only every return numbers (or infinities, or NaN's).

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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