CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Guest

    How to expand array?

    Is there any easy way to make array one size biger? without using loop or redim?


  2. #2
    Guest

    Re: How to expand array?

    you can use variant datatype...

    Dim vntTest As Variant

    vntTest(0) = 1
    vntTest(1) = "test"


  3. #3
    Join Date
    Oct 1999
    Posts
    25

    Re: How to expand array?

    The variant datatype cannot be used as you described. If you want to resize an array, it must be declared as a dynamic array. Then it can be appropriately redimensioned.

    Dim MyDynamicArray() 'Variant datatype is the default

    ReDim MyDynamicArray(10)

    If the Option Base is set to 0, the default, the array items will be numbered 0 to 9. If later in your code you want to add values but do not want to lose the contents of the array you can use the Preserve keyword ...

    ReDim Preserve MyDynamicArray(15)


  4. #4
    Guest

    Re: How to expand array?

    Sky,
    what do you mean by "I can't use the Variant method"? I am using it right now and I have no problem with it. Your way would work too but before you issue a redim statement, you need to save your existing data to a temporary array because it will destroy everythings you have in that array...


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

Featured