Results 1 to 9 of 9

Thread: passing arrayllist value into another class

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2009
    Posts
    135

    passing arrayllist value into another class

    anybody how to pass arraylist value in to another class?

    pls help..

    tnx

  2. #2
    Master Of Orion ForumAccount's Avatar
    Join Date
    Jan 2009
    Location
    Canada
    Posts
    2,802

    Re: passing arrayllist value into another class

    You'll have to be way more specific then that. Are you talking about the constructor or a method perhaps? With that said, it's not any different from passing any other argument type.

  3. #3
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: passing arrayllist value into another class

    Also, there is usually no good reason to be using ArrayList - you should use a strongly typed List(Of T). So for example if your ArrayList contains just string values then you would have:
    vb Code:
    1. Dim MyList As New List(Of String)
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Aug 2009
    Posts
    135

    Re: passing arrayllist value into another class

    yes,i only pass string value and i stored it into an arraylist..and i wanted to access this arraylist value into another form..is arraylist the right to use?

    tnx

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Aug 2009
    Posts
    135

    Re: passing arrayllist value into another class

    by the way i am using VB2003..i try list but i think this not supported in this version..

  6. #6
    Pro Grammar chris128's Avatar
    Join Date
    Jun 2007
    Location
    England
    Posts
    7,604

    Re: passing arrayllist value into another class

    Ah, no its not supported in that version unfortunately. If you mark your thread as VS 2003 then people will know not to suggest things that are not available to you.

    Anyway, you need to explain what exactly you are trying to do but speaking in general, to pass a value in an ArrayList to anything (a class, a method, whatever) you just do this:
    vb Code:
    1. MyArrayList.Item(0)
    That's assuming you want the first item in the list, if you wanted the second item it would be:
    vb Code:
    1. MyArrayList.Item(1)

    If you wanted to do something for every single item in the list, you could either pass the actual ArrayList itself to your class/method and then that would do a loop or you could do a loop and call the method, like so:
    vb Code:
    1. For Each str As String In MyArrayList
    2.     MyMethod(str) 'calling a method and passing the current string in the loop to it
    3. End For

    Thats all a bit general but its hard to give you anything more specific when you havent given us any information..
    My free .NET Windows API library (Version 2.2 Released 12/06/2011)

    Blog: cjwdev.wordpress.com
    Web: www.cjwdev.co.uk


  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Aug 2009
    Posts
    135

    Re: passing arrayllist value into another class

    thank you very much chris128

    that would be a big help! it solved my problem..

    tnx
    glen

  8. #8
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: passing arrayllist value into another class

    Give class2 a property of type List() and then assign your array list to that property.

    Dim c2 As New Class2
    c2.TheFinalList = myArrayList

  9. #9

    Thread Starter
    Addicted Member
    Join Date
    Aug 2009
    Posts
    135

    Re: passing arrayllist value into another class

    thanks mendhak..

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