locked
How to make dynamic array RRS feed

  • Question

  • User-318218893 posted

    Hello Everybody,

     

    I want to ask how to create dynamic array and i can fill array in the lastindex. So i do not declare number element of array because my array is not sure the index. I try like this but get the error problem... Sory if my english is not good

    Dim arr() As String

    arr(arr.getLowerBound(0)) = "A"

     MsgBox(arr().getLowerBound(0))

    Thanks everybody 

     

    Saturday, April 19, 2008 7:59 AM

Answers

  • User-2005691517 posted

     You can use an arraylist instead

    Dim myAL As New ArrayList()
    myAL.Add("The")
    myAL.Add("quick")
    myAL.Add("brown")
    myAL.Add("fox")
    myAL.Add("jumped")
    myAL.Add("over")
    myAL.Add("the")
    myAL.Add("lazy")
    myAL.Add("dog")

    ' Copies the elements of the ArrayList to a string array.
    Dim myArr As String() = CType(myAL.ToArray(GetType(String)), String())

     http://msdn.microsoft.com/en-us/library/fcyyh2hb.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, April 19, 2008 8:33 AM

All replies

  • User-2005691517 posted

     You can use an arraylist instead

    Dim myAL As New ArrayList()
    myAL.Add("The")
    myAL.Add("quick")
    myAL.Add("brown")
    myAL.Add("fox")
    myAL.Add("jumped")
    myAL.Add("over")
    myAL.Add("the")
    myAL.Add("lazy")
    myAL.Add("dog")

    ' Copies the elements of the ArrayList to a string array.
    Dim myArr As String() = CType(myAL.ToArray(GetType(String)), String())

     http://msdn.microsoft.com/en-us/library/fcyyh2hb.aspx

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, April 19, 2008 8:33 AM
  • User1693635062 posted

    That's pretty cleaver there Prashant,

     Can you beleive I used to create a listbox and set it visible=false and use it as a Dynamic array... HAHAH I was such a newb!

    Monday, April 21, 2008 2:16 PM
  • User1589032278 posted

    thanks dood

    Thursday, December 11, 2008 10:19 AM