Array nullexception

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • latin & geek via DotNetMonster.com

    #1

    Array nullexception

    dear all,

    hi. i have a little sub routine which works fine in my dummy test program,
    but when i insert it in my main program it throws errors.

    this is the subroutine:

    Public Sub TagListing()
    'adds a tag category from the tag stack into the unique tag
    collection
    Try
    TagStrings.Push (JustForArrayIn clusion)
    TagStrings.Copy To(OldTags, moveit)
    moveit = moveit + 1
    Catch ex As Exception
    MsgBox(ex.ToStr ing, MsgBoxStyle.OKO nly, errortitle)
    End Try
    End Sub


    i get this error at the CopyTo line:

    SystemArgumentN ullException: Value cannot be null
    Parameter name: array
    at Systems.Collect ions.Stack.Copy To(Array array,Int32 index)
    at Catalogue.Modul e1.TagListing() [....] at line 137

    i've declared my array like this in the same module:
    'Array to hold all the unique tag categories.
    'Used In: TagListing(), BtF3OldTags_Cli ck, Form4_Load
    Public OldTags As String()

    moveit is correctly at zero the first time around (it's called from a FOR
    loop), so i don't understand what the problem is!

    can someone please help?

    also, one final doubt, what's the difference between
    Dim MyArray( ) as String
    &
    Dim MyArray as String( ) ?

    thanks a lot!

    --
    Message posted via DotNetMonster.c om
    Best online pokies for real money in Australia and learn about safety and game mechanics in this comprehensive guide.


  • =?UTF-8?B?R8O2cmFuIEFuZGVyc3Nvbg==?=

    #2
    Re: Array nullexception

    latin & geek via DotNetMonster.c om wrote:
    dear all,
    >
    hi. i have a little sub routine which works fine in my dummy test program,
    but when i insert it in my main program it throws errors.
    >
    this is the subroutine:
    >
    Public Sub TagListing()
    'adds a tag category from the tag stack into the unique tag
    collection
    Try
    TagStrings.Push (JustForArrayIn clusion)
    TagStrings.Copy To(OldTags, moveit)
    moveit = moveit + 1
    Catch ex As Exception
    MsgBox(ex.ToStr ing, MsgBoxStyle.OKO nly, errortitle)
    End Try
    End Sub
    >
    >
    i get this error at the CopyTo line:
    >
    SystemArgumentN ullException: Value cannot be null
    Parameter name: array
    at Systems.Collect ions.Stack.Copy To(Array array,Int32 index)
    at Catalogue.Modul e1.TagListing() [....] at line 137
    >
    i've declared my array like this in the same module:
    'Array to hold all the unique tag categories.
    'Used In: TagListing(), BtF3OldTags_Cli ck, Form4_Load
    Public OldTags As String()
    This declares a reference to the array, but it doesn't create the array
    itself. You also need to create the array:

    OldTags = New String()
    moveit is correctly at zero the first time around (it's called from a FOR
    loop), so i don't understand what the problem is!
    >
    can someone please help?
    >
    also, one final doubt, what's the difference between
    Dim MyArray( ) as String
    This is the older syntax, inherited from VB 6.
    &
    Dim MyArray as String( ) ?
    This is the new syntax introduced in VS.NET. It's more consistent with
    how .NET works, as an array in .NET are just another data type, and not
    a special kind of variable as in VB 6.

    --
    Göran Andersson
    _____
    Göran Anderssons privata hemsida.

    Comment

    • =?UTF-8?B?R8O2cmFuIEFuZGVyc3Nvbg==?=

      #3
      Re: Array nullexception

      Göran Andersson wrote:
      >i've declared my array like this in the same module:
      > 'Array to hold all the unique tag categories. 'Used In:
      >TagListing() , BtF3OldTags_Cli ck, Form4_Load
      > Public OldTags As String()
      >
      This declares a reference to the array, but it doesn't create the array
      itself. You also need to create the array:
      >
      OldTags = New String()
      Oops. Of course you need to specify a size for the array:

      OldTags = New String(42)

      --
      Göran Andersson
      _____
      Göran Anderssons privata hemsida.

      Comment

      • latin & geek via DotNetMonster.com

        #4
        Re: Array nullexception

        oh, i see! thanks... you're absolutely right, it works once i do that. thanks
        a lot!

        Göran Andersson wrote:
        >>i've declared my array like this in the same module:
        >> 'Array to hold all the unique tag categories. 'Used In:
        >[quoted text clipped - 5 lines]
        >>
        >OldTags = New String()
        >
        >Oops. Of course you need to specify a size for the array:
        >
        >OldTags = New String(42)
        >
        --
        Message posted via http://www.dotnetmonster.com

        Comment

        • Branco Medeiros

          #5
          Re: Array nullexception

          Göran Anderssonwrote:
          <snip>
          This declares a reference to the array, but it doesn't create the array
          itself. You also need to create the array:
          >
          OldTags = New String()
          <snip>

          The instance will be created also if you specify the upper bound of
          the array. That can be -1 (yep, you read it right) to specify an empty
          (but valid) array:

          Dim OldTags As String(-1)

          <snip>
          Dim MyArray( ) as String
          >
          This is the older syntax, inherited from VB 6.
          <snip>
          Dim MyArray as String( ) ?
          >
          This is the new syntax introduced in VS.NET. It's more consistent with
          how .NET works, as an array in .NET are just another data type, and not
          a special kind of variable as in VB 6.
          <snip>

          Nope, they represent valid syntax both in VB 6 *and* VB.Net. There
          are folks who prefer their array indicator in the variable name
          (because the *variable* is the array, not the String). The syntax you
          suggest was born (actually in VB 5, if I recall correctly) to allow
          the declaration of functions returning arrays (which the other syntax
          can't express).

          The OP doesn't specify the VB.Net version being used, but it seems
          VB2005 introduces the following syntax:

          Dim MyArray(0 To UpperBound) As SomeType

          Which is regarded more readable than Dim MyArray(UpperBo und).

          Just a bit o trivia thrown in...

          Regards,

          Branco.

          Comment

          • latin & geek via DotNetMonster.com

            #6
            Re: Array nullexception

            wow. i didnt know this dot net business had a history and tradition thing
            happening!! :))

            thanks a lot. the (-1) declaration may be just what i need for another part
            of the code - am off to try it.

            gracias.


            Branco Medeiros wrote:
            >Göran Anderssonwrote:
            --
            Message posted via DotNetMonster.c om
            Best online pokies for real money in Australia and learn about safety and game mechanics in this comprehensive guide.


            Comment

            Working...