declaring array of type Dim q As Double(,)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • mark

    declaring array of type Dim q As Double(,)

    When I declare an array as double(,) then try to use it I get an error:
    "Object reference not set to an instance of an object."
    I have found that I can redim the array and all is well. Is my approach
    proper here or is the a better way for setting the instance of this specific
    format for an array.

    --
    mark
  • Herfried K. Wagner [MVP]

    #2
    Re: declaring array of type Dim q As Double(,)

    "mark" <mark@discussio ns.microsoft.co m> schrieb:[color=blue]
    > When I declare an array as double(,) then try to use it I get an error:
    > "Object reference not set to an instance of an object."
    > I have found that I can redim the array and all is well. Is my approach
    > proper here or is the a better way for setting the instance of this
    > specific
    > format for an array.[/color]

    \\\
    Dim adbl(9, 9) As Double
    ///

    .... will create a 10 x 10 double array.

    --
    M S Herfried K. Wagner
    M V P <URL:http://dotnet.mvps.org/>
    V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

    Comment

    • mark

      #3
      Re: declaring array of type Dim q As Double(,)

      Yes. However, in reference to our earlier discussion I want to be able to
      avoid the latebinding error I get when I pass an array declared in this
      fashion. I am guessing that I should continue to use the a(9,9) as double
      format for declaring arrays and I should use the "a as double(,)" format for
      typing the procedure arguments. Do I have this right?

      "Herfried K. Wagner [MVP]" wrote:
      [color=blue]
      > "mark" <mark@discussio ns.microsoft.co m> schrieb:[color=green]
      > > When I declare an array as double(,) then try to use it I get an error:
      > > "Object reference not set to an instance of an object."
      > > I have found that I can redim the array and all is well. Is my approach
      > > proper here or is the a better way for setting the instance of this
      > > specific
      > > format for an array.[/color]
      >
      > \\\
      > Dim adbl(9, 9) As Double
      > ///
      >
      > .... will create a 10 x 10 double array.
      >
      > --
      > M S Herfried K. Wagner
      > M V P <URL:http://dotnet.mvps.org/>
      > V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
      >
      >[/color]

      Comment

      • Jay B. Harlow [MVP - Outlook]

        #4
        Re: declaring array of type Dim q As Double(,)

        Mark,[color=blue]
        > I am guessing that I should continue to use the a(9,9) as double
        > format for declaring arrays[/color]
        Yes you either need to give the size of the array or initialize it when you
        declare the array itself. Going back to your original question, you
        initialized the array with "{{1, 2}, {3, 4}, {5, 6}}" which will implicitly
        set the size.

        Dim a(,) As Double = {{1, 2}, {3, 4}, {5, 6}}

        Using ReDim will also initialize the array.

        ReDim a(9,9)
        [color=blue]
        > I should use the "a as double(,)" format for
        > typing the procedure arguments.[/color]

        Yes you need to use "a as double(,)" for parameters/arguments so the
        compiler knows the specific type of the array, size is not important here,
        as the array itself knows how big it is...

        Private Sub T1(ByVal a As Double(,))
        Dim i, j As Integer
        For i = 0 To 2
        For j = 0 To 2
        a(i, j) = 2 * a(i, j) Underlined as latebinding error
        Next
        Next
        End Sub

        Hope this helps
        Jay

        "mark" <mark@discussio ns.microsoft.co m> wrote in message
        news:2B5366F9-FA5D-4A68-8E91-B5AE69F32ED8@mi crosoft.com...[color=blue]
        > Yes. However, in reference to our earlier discussion I want to be able to
        > avoid the latebinding error I get when I pass an array declared in this
        > fashion. I am guessing that I should continue to use the a(9,9) as double
        > format for declaring arrays and I should use the "a as double(,)" format
        > for
        > typing the procedure arguments. Do I have this right?
        >
        > "Herfried K. Wagner [MVP]" wrote:
        >[color=green]
        >> "mark" <mark@discussio ns.microsoft.co m> schrieb:[color=darkred]
        >> > When I declare an array as double(,) then try to use it I get an error:
        >> > "Object reference not set to an instance of an object."
        >> > I have found that I can redim the array and all is well. Is my approach
        >> > proper here or is the a better way for setting the instance of this
        >> > specific
        >> > format for an array.[/color]
        >>
        >> \\\
        >> Dim adbl(9, 9) As Double
        >> ///
        >>
        >> .... will create a 10 x 10 double array.
        >>
        >> --
        >> M S Herfried K. Wagner
        >> M V P <URL:http://dotnet.mvps.org/>
        >> V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
        >>
        >>[/color][/color]


        Comment

        Working...