Results 1 to 3 of 3

Thread: ArrayList inside Structure/Class

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Apr 2005
    Posts
    18

    Resolved ArrayList inside Structure/Class

    Is it not possible to use an ArrayList inside of a Structure or a Class?

    I keep getting 'Object reference not set to instance of an object'

    I am using New.

    i.e.

    Stucture ABC
    Dim al as ArrayList
    End Structure


    Private Sub X()

    Dim Struct1 as New ABC

    Struct1.al.Add("anything")

    End Sub
    Last edited by sage; Jun 30th, 2005 at 12:50 PM.

  2. #2
    Fanatic Member
    Join Date
    May 2005
    Posts
    898

    Re: ArrayList inside Structure/Class

    It's because the arraylist hasn't been instanciated yet.

    I'm not a 100% sure if you can do this inside a Structure, if not then use a Class instead.
    VB Code:
    1. Structure ABC
    2.     Public al as ArrayList = New ArrayList
    3. End Structure

    or

    VB Code:
    1. Structure ABC
    2.     Public al as ArrayList
    3.  
    4.     Public Sub New()
    5.         al = New ArrayList
    6.     End Sub
    7. End Structure
    "so just keep in mind that fantasy is not the same as realtiy and make sure u remember that wii sports may be fun but u cant count on it as exercise ok cool bye" - HungarianHuman

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Apr 2005
    Posts
    18

    Re: ArrayList inside Structure/Class

    Your first solution works for a class. Thanks grillkip.

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