Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

How to: Declare an Array Variable 

You declare an array variable the same way as any other variable, using the Dim statement. You follow the variable name with one or more pairs of parentheses to indicate that it is to hold an array rather than a scalar (a variable containing a single value).

Declaring Array Variables

To declare a one-dimensional array variable

  • In your declaration, add one pair of parentheses after the variable name. The following example declares a variable to hold a one-dimensional array with elements of the Double Data Type (Visual Basic).

    Dim cargoWeights() As Double
    

    The preceding example declares an array variable but does not assign an array to it. You still must create a one-dimensional array, initialize it, and assign it to cargoWeights.

To declare a multidimensional array variable

  • In your declaration, add one pair of parentheses after the variable name and place commas inside the parentheses to separate the dimensions. The following example declares a variable to hold a four-dimensional array with elements of the Short Data Type (Visual Basic).

    Dim atmospherePressures(,,,) As Short
    

    The preceding example declares an array variable but does not assign an array to it. You still must create a four-dimensional array, initialize it, and assign it to atmospherePressures.

To declare a jagged array variable

  • In your declaration, add as many pairs of parentheses after the variable name as there are levels of nested arrays. The following example declares a variable to hold an array of arrays of arrays (an array, each element of which is an array, each element of which is an array), with the innermost array having elements of the Byte Data Type (Visual Basic).

    Dim inquiriesByYearMonthDay()()() As Byte
    

    The preceding example declares an array variable but does not assign an array to it. You still must create an array of arrays of arrays, initialize it, and assign it to inquiriesByYearMonthDay.

See Also

Community Additions

ADD
Show:
© 2015 Microsoft