+ Reply to Thread
Results 1 to 4 of 4

Dimension Arguments?

  1. #1
    Registered User
    Join Date
    10-16-2006
    Location
    Shreveport, LA
    Posts
    32

    Dimension Arguments?

    So, the more I learn about Excel the more I learn how little I know about Excel.


    Dim test as long ' variable declaration
    Dim test(3) as long 'what does this add to the variable? How can this be used? Is this a "variable with an argument"? Can all types of declarations be used?


    ww
    Excel 2010

  2. #2
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Dimension Arguments?

    ww2u,

    That turns the variable into an array. Arrays have a number of elements that they can store. When you Dim test(3), you are saying "I want an array starting at element 0 and going to element 3, so it will have 4 elements: 0, 1, 2, and 3"
    As for what types of declarations can be used, yes they can be any type. However, if you type an array, then every element within the array must be that type. For example, element 0 couldn't be a Long while element 1 was a string. You can get around this (have an array with multiple types) by declaring it as Variant (which is the same as not typing the variable in the first place).

    Generally speaking, I find it is better practice to declare both the lower and upper bounds of an array when you dimension the variable, like Dim test(1 to 3) so that I know it has exactly three elements starting at 1. You can also declare multi-dimensional arrays, like so:
    Dim test(1 to 3, 1 to 2)

    This means it is an array with two dimensions. Think of it as a table from cells A1:B3, there are three rows and two columns. You can have 3 dimensional arrays and higher also. You can also have arrays of arrays if you'd like. It just depends on what your coding preferences/needs are.
    Hope that helps,
    ~tigeravatar

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  3. #3
    Forum Expert tigeravatar's Avatar
    Join Date
    03-25-2011
    Location
    Colorado, USA
    MS-Off Ver
    Excel 2003 - 2013
    Posts
    5,361

    Re: Dimension Arguments?

    Here's an example of using an array:
    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    10-16-2006
    Location
    Shreveport, LA
    Posts
    32

    Re: Dimension Arguments?

    Cool! Now the fun begins.


    ww

+ 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