none
Create ArrayList RRS feed

  • Question



  • Hi all, I have the following question, is it possible to create an ArrayList in VBA ?, greetings
    Thursday, September 25, 2014 11:17 PM

Answers

  • Are you referring to the ArrayList Object?

    If so, below is an example on how to use that Object:

    Sub testArrayList()
        Dim ArrList As Object, ArrList2 As Object
        
        Set ArrList = CreateObject("System.Collections.ArrayList")
        
        ArrList.Add ("Line1")
        ArrList.Add ("Line2")
        ArrList.Add ("Line3")
        
        Set ArrList2 = ArrList.GetRange(1, 1)
        
        MsgBox Join(ArrList.ToArray(), vbNewLine)
        MsgBox Join(ArrList2.ToArray(), vbNewLine)
            
    End Sub

    To help you more specific, you need to give more detail on what exactly you want to create in the ArrayList.

    Hope this helps,


    Daniel van den Berg | Washington, USA | "Anticipate the difficult by managing the easy"

    Please vote an answer helpful if they helped. Please mark an answer(s) as an answer when your question is being answered.


    • Edited by danishaniModerator Friday, September 26, 2014 2:51 AM spelling
    • Marked as answer by aslf010990 Friday, September 26, 2014 2:09 PM
    Friday, September 26, 2014 2:51 AM
    Moderator
  • Are we talking the .NET ArrayList? If so, yes it is possible as long as .NET framework is installed on your machine - which I believe Windows comes with from Win XP onwards.

    You can use early binding and late binding.

    Early binding:

    In the Visual Basic Editor in Excel click on the Tools -> References. Scroll down to mscorlib.dll and tick the box. If you hit F2 to open the Object Browser and type: ArrayList in the classes box you can see what members are available with intelli-sense for your ArrayList class.

    With early binding you can initialize an ArrayList like this:

    Dim arrList as new ArrayList

    when you then type:

    arrList.

    you should see the available members listed in the intellli-sense box.

    If you want to use late binding - see above dinishi's answer.


    • Marked as answer by aslf010990 Friday, September 26, 2014 2:08 PM
    Friday, September 26, 2014 7:10 AM

All replies

  • Are you referring to the ArrayList Object?

    If so, below is an example on how to use that Object:

    Sub testArrayList()
        Dim ArrList As Object, ArrList2 As Object
        
        Set ArrList = CreateObject("System.Collections.ArrayList")
        
        ArrList.Add ("Line1")
        ArrList.Add ("Line2")
        ArrList.Add ("Line3")
        
        Set ArrList2 = ArrList.GetRange(1, 1)
        
        MsgBox Join(ArrList.ToArray(), vbNewLine)
        MsgBox Join(ArrList2.ToArray(), vbNewLine)
            
    End Sub

    To help you more specific, you need to give more detail on what exactly you want to create in the ArrayList.

    Hope this helps,


    Daniel van den Berg | Washington, USA | "Anticipate the difficult by managing the easy"

    Please vote an answer helpful if they helped. Please mark an answer(s) as an answer when your question is being answered.


    • Edited by danishaniModerator Friday, September 26, 2014 2:51 AM spelling
    • Marked as answer by aslf010990 Friday, September 26, 2014 2:09 PM
    Friday, September 26, 2014 2:51 AM
    Moderator
  • Are we talking the .NET ArrayList? If so, yes it is possible as long as .NET framework is installed on your machine - which I believe Windows comes with from Win XP onwards.

    You can use early binding and late binding.

    Early binding:

    In the Visual Basic Editor in Excel click on the Tools -> References. Scroll down to mscorlib.dll and tick the box. If you hit F2 to open the Object Browser and type: ArrayList in the classes box you can see what members are available with intelli-sense for your ArrayList class.

    With early binding you can initialize an ArrayList like this:

    Dim arrList as new ArrayList

    when you then type:

    arrList.

    you should see the available members listed in the intellli-sense box.

    If you want to use late binding - see above dinishi's answer.


    • Marked as answer by aslf010990 Friday, September 26, 2014 2:08 PM
    Friday, September 26, 2014 7:10 AM
  • ok , thank you very much
    Friday, September 26, 2014 2:08 PM