Page 1 of 1

Question about ReDim

Posted: Wed Mar 29, 2006 8:48 pm
by fsw
The following is from the HELP file:
  • If ReDim is used with a multi-dimension array, only its last dimension can be changed.
What is ment by that?

If I have a multidimensional array like:

Code: Select all

Dim MYarray.l(2,2)
I get these fields/items/elements (whatever):

Code: Select all

MYarray Index 0 = Position 1, Position 2
MYarray Index 1 = Position 1, Position 2
MYarray Indexl 2 = Position 1, Position 2
So when it's redimmed to:

Code: Select all

ReDim MYarray(4,4)
I get these fields/items/elements (whatever):

Code: Select all

MYarray Index 0 = Position 1, Position 2
MYarray Index 1 = Position 1, Position 2
MYarray Index 2 = Position 1, Position 2
MYarray Index 3 = NoPosition, Position 2
MYarray Index 4 = NoPosition, Position 2
or what?

Posted: Wed Mar 29, 2006 10:35 pm
by Fred
You can only change the last dimension:

Code: Select all

Dim array(10, 2)
ReDim array(10, 40) ; Ok
ReDim array(20, 40) ; Not Ok

Posted: Wed Mar 29, 2006 10:38 pm
by Shannara
ooo, VB6 have this limitation as well, but there was a workaround posted to get around this.

Will there be a way to redim any dimension of an array in PB in the future?

Posted: Wed Mar 29, 2006 10:45 pm
by Fred
The problem is mainly a performance issue, so i don't think we will change it. You can still Dim it again if you want to change everything.

Posted: Thu Mar 30, 2006 3:32 am
by fsw
Fred wrote:You can only change the last dimension:

Code: Select all

Dim array(10, 2)
ReDim array(10, 40) ; Ok
ReDim array(20, 40) ; Not Ok
Thanks for the explanation.

Maybe it's a good idea to put the code above into the help file.

Posted: Wed Apr 08, 2009 9:43 am
by Kwai chang caine
Hi at all

Somebody have a code, who do a REDIM a string array and/or integer for all the dimension ???? 8)

Perhaps with SWAP of memory, in another array or another thing. :roll:
Because the manipulation of memory is again too difficult for me :oops: