Results 1 to 5 of 5

Thread: Easy - array dimensions

  1. #1
    james007lamb
    Guest

    Easy - array dimensions

    i am just wondering how vb sets up an array, if i want to set up and array like the following, with 2 rows and 4 columns

    1 1 1 1
    1 1 1 1

    do i set it up as Dim Matrix(1 To 2, 1 To 4) As Double

    or as Dim Matrix(1 To 4, 1 To 2) As Double

  2. #2
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Dim Matrix(1 To 2, 1 To 4) As Double

    the first dimension, 1 to 2 will give you:

    1
    2

    The second, 1 4, will give the first dimension, dimension (I wish I knew technical terms) so it'll become

    1 - 1 2 3 4
    2 - 1 2 3 4
    My evil laugh has a squeak in it.

    kristopherwilson.com

  3. #3
    C# Aficionado Lord_Rat's Avatar
    Join Date
    Sep 2001
    Location
    Cave
    Posts
    2,497
    Either depending on how you use, but if you want in the x,y co-ordinate system, use:

    Dim Matrix(1 To 2, 1 To 4) As Double
    Need to re-register ASP.NET?
    C:\WINNT\Microsoft.NET\Framework\v#VERSIONNUMBER#\aspnet_regiis -i

    (Edit #VERSIONNUMBER# as needed - do a DIR if you don't know)

  4. #4
    -= B u g S l a y e r =- peet's Avatar
    Join Date
    Aug 2000
    Posts
    9,629
    MSDN

    Multidimensional Arrays
    Sometimes you need to keep track of related information in an array. For example, to keep track of each pixel on your computer screen, you need to refer to its X and Y coordinates. This can be done using a multidimensional array to store the values.

    With Visual Basic, you can declare arrays of multiple dimensions. For example, the following statement declares a two-dimensional 10-by-10 array within a procedure:

    Static MatrixA(9, 9) As Double

    Either or both dimensions can be declared with explicit lower bounds:

    Static MatrixA(1 To 10, 1 To 10) As Double

    You can extend this to more than two dimensions. For example:

    Dim MultiD(3, 1 To 10, 1 To 15)

    This declaration creates an array that has three dimensions with sizes 4 by 10 by 15. The total number of elements is the product of these three dimensions, or 600.

    Note When you start adding dimensions to an array, the total storage needed by the array increases dramatically, so use multidimensional arrays with care. Be especially careful with Variant arrays, because they are larger than other data types.
    -= a peet post =-

  5. #5
    Megatron
    Guest

    Re: Easy - array dimensions

    Originally posted by james007lamb
    do i set it up as Dim Matrix(1 To 2, 1 To 4) As Double

    or as Dim Matrix(1 To 4, 1 To 2) As Double
    Both of them will work.

    Dim Matrix(1 To 2, 1 To 4) will produce:

    1 1
    1 1
    1 1
    1 1

    Dim Matrix(1 To 4, 1 To 2) will produce

    1 1 1 1
    1 1 1 1

Posting Permissions

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



Click Here to Expand Forum to Full Width