Results 1 to 5 of 5

Thread: Redim giving error

  1. #1

    Thread Starter
    Frenzied Member Blobby's Avatar
    Join Date
    Oct 2001
    Location
    England
    Posts
    1,512

    Redim giving error

    I am trying to create and resize on the fly a multi dimensional array and im getting an error with the line:

    VB Code:
    1. ReDim Preserve ResultsArray(Arrayindex, 4)

    Arrayindex contains the number 1 at the time of the error and worked first time thru with Arrayindex set to 0.

    I am declaring the array in the globals as Dim ResultsArray()
    and then the code at the time im getting the error on is redimensioning as it finds rows. Any ideas anyone? thanx
    There are 3 types of people in this world.........those that can count, and those that can't.

    Blobby

  2. #2
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687
    Search this board long enough and you'll find out that this is one of the biggest things that sticks on our craw. In VB, you can't ReDim the first element of an array... only the second. It sucks I know, that's the way it is.

    Would it be possible to switch your elements?
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  3. #3

    Thread Starter
    Frenzied Member Blobby's Avatar
    Join Date
    Oct 2001
    Location
    England
    Posts
    1,512
    Techgnome.....brilliant answer....thanks a lot......i knew it but its late and im not thinking straight. Maybe i should start again when ive got a clear head....cheers chap
    There are 3 types of people in this world.........those that can count, and those that can't.

    Blobby

  4. #4
    Super Moderator Shaggy Hiker's Avatar
    Join Date
    Aug 2002
    Location
    Idaho
    Posts
    40,106
    You can redim the first element, but not the way you want to. The problem is that you can't use Redim Preserve on the first element. However, you can simply Redim the first element. Unfortunately, that will delete all the data from the array. The solution, is to copy the data into a temporary array, redim the array, and copy the data back into the original array. This is slow and cumbersome, but can be split into a function, I would think.

  5. #5

    Thread Starter
    Frenzied Member Blobby's Avatar
    Join Date
    Oct 2001
    Location
    England
    Posts
    1,512

    Angry

    Yep.....its just another point to tell Microsoft that they have written a load of bo*****. Why cant they write stuff in a logical way????? You just dont think as colums first then rows,....we are all taught in a way like Excel looks......rows first param....then columns second....its a lot harder getting to grips with columns then rows.
    There are 3 types of people in this world.........those that can count, and those that can't.

    Blobby

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