Results 1 to 6 of 6

Thread: [RESOLVED] Changing size of array

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    May 2007
    Location
    Belgium
    Posts
    156

    Resolved [RESOLVED] Changing size of array

    I am using an array in loop and I need to change it's size to make the program use less memory resources.

    Redim only works 1 time as I tried it.

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: Changing size of array

    You cannot resize a static array. Static arrays are declared like the following:
    Code:
    Dim ABC(100) As Long ' static array
    Dim XYZ() As Long '  dynamic array
    ReDim resizes dynamic arrays without trying to save the existing array data.
    ReDim Preserve resizes and saves existing data.

    I think we may need to see your loop.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3
    Frenzied Member Jim Davis's Avatar
    Join Date
    Mar 2001
    Location
    Mars base one Username: Jim Davis Password: yCrm33
    Posts
    1,284

    Re: Changing size of array

    vb Code:
    1. Dim myArray() 'Dont specify any element number. It will be a dynamic array.
    2. Redim myArray(1 To 100) 'gives a dimension of 100 elements. it will clean up the array also.
    3. ReDim Preserve myArray(1 To 99) 'will reduce the array to 99 elements. the 'Preserve' property will preserves the elements in the array.

    Is this you are looking for?

    LaVolpe is the winner (i was too late)
    Last edited by Jim Davis; Dec 21st, 2008 at 04:37 AM.

  4. #4
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: Changing size of array

    [Pedantic]
    Code:
    ReDim myArray(100)
    gives a Dimension of 101 elements (0 to 100) unless you've specified Option Base 1 in the General Section of the Form
    [/Pedantic]


  5. #5
    Frenzied Member Jim Davis's Avatar
    Join Date
    Mar 2001
    Location
    Mars base one Username: Jim Davis Password: yCrm33
    Posts
    1,284

    Re: Changing size of array

    @Doogle is right, i was forgot to mention. (remarks fixed as well).

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    May 2007
    Location
    Belgium
    Posts
    156

    Re: Changing size of array

    Yeah I was using Dim MyArray(32) as string.
    Thanks all!
    resolved

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