ReDim an Array Problems

ReDim an Array Problems

Anonymous
Not applicable
642 Views
5 Replies
Message 1 of 6

ReDim an Array Problems

Anonymous
Not applicable
I'm trying to Redim an array.

I first define it as

dim arProps() as string

later in the code I redim it as

ReDim Preserve arProps(0 To ListBox1.ListCount, 0 To 1)

where ListBox1.Listcount is usually around 25 to 35

however I only end up putting in one row of info

now later in the code I want to strip out the extra blank cells so I redim
to

ReDim Preserve arProps(0 To EmptyArraySpot, 0 To 1)

where the first time around EmptyArraySpot is 0

this is where the error occurs

I'm assuming arProps(0 to 0, 0 to 1) is illegal but why? It's simply a one
row, two column array...

ReDim Preserve arProps(EmptyArraySpot, 0 To 1) gives the same error
(subscript out of range)

--
Sean Dotson, PE
http://www.sdotson.com
Check the Inventor FAQ for most common questions
www.sdotson.com/faq.html
-----------------------------------------------------------------------
0 Likes
643 Views
5 Replies
Replies (5)
Message 2 of 6

Anonymous
Not applicable
Try switching the columns and rows. You can only change the last number in
the array.

From Help
"If you use the Preserve keyword, you can resize only the last array
dimension and you can't change the number of dimensions at all. For example,
if your array has only one dimension, you can resize that dimension because
it is the last and only dimension. However, if your array has two or more
dimensions, you can change the size of only the last dimension and still
preserve the contents of the array. The following example shows how you can
increase the size of the last dimension of a dynamic array without erasing
any existing data contained in the array.
ReDim X(10, 10, 10)
. . .
ReDim Preserve X(10, 10, 15)"Kathy Johnson
0 Likes
Message 3 of 6

Anonymous
Not applicable
OK I guess I missed that part in the help (it was late last night).

Well that stinks. I don't see why you shouldn't be allowed to resize the
first dimension...

Guess I'll have to do some array trickery...

Thanks Kathy..
--
Sean Dotson, PE
http://www.sdotson.com
Check the Inventor FAQ for most common questions
www.sdotson.com/faq.html
"...and quit driving 50MPH in the left lane!!!"
"..and quit driving in the left hand lne at 50 MPH!!"
-----------------------------------------------------------------------
"KJohnson" wrote in message
news:584E3AE907EDB54053EA5476603833D0@in.WebX.maYIadrTaRb...
> Try switching the columns and rows. You can only change the last number
in
> the array.
>
> From Help
> "If you use the Preserve keyword, you can resize only the last array
> dimension and you can't change the number of dimensions at all. For
example,
> if your array has only one dimension, you can resize that dimension
because
> it is the last and only dimension. However, if your array has two or more
> dimensions, you can change the size of only the last dimension and still
> preserve the contents of the array. The following example shows how you
can
> increase the size of the last dimension of a dynamic array without erasing
> any existing data contained in the array.
> ReDim X(10, 10, 10)
> . . .
> ReDim Preserve X(10, 10, 15)"Kathy Johnson
>
>
0 Likes
Message 4 of 6

Anonymous
Not applicable
No problem. I hope it clears up your error.

Kathy Johnson
0 Likes
Message 5 of 6

Anonymous
Not applicable
Sean,

I have done the following in AutoCAD and it works fine

Dim mstrLayerNameArray() As String

'redimension array to hold states of all layers
ReDim mstrLayerNameArray(ThisDrawing.Layers.Count - 1, 6)

The first dimension designates the rows and the second is columns. Now I have re-dimensioned the columns in this example but I don't think once you have set it for the first time that you can change it after that.

HTH

Joe
--
0 Likes
Message 6 of 6

Anonymous
Not applicable
Right... the problem is I already had it dimensioned...I figured out a way
around it however. Thanks.

--
Sean Dotson, PE
http://www.sdotson.com
Check the Inventor FAQ for most common questions
www.sdotson.com/faq.html
-----------------------------------------------------------------------
"joesu" wrote in message
news:f16f0a9.3@WebX.maYIadrTaRb...
> Sean,
> I have done the following in AutoCAD and it works fine
>
>
> Dim mstrLayerNameArray() As String 'redimension array to hold states of
all layers
> ReDim mstrLayerNameArray(ThisDrawing.Layers.Count - 1, 6)
> The first dimension designates the rows and the second is columns. Now I
have re-dimensioned the columns in this example but I don't think once you
have set it for the first time that you can change it after that.
> HTH
>
> Joe
> --
>
0 Likes