Question about ReDim

Everything else that doesn't fall into one of the other PB categories.
User avatar
fsw
Addict
Addict
Posts: 1603
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Question about ReDim

Post 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?
Fred
Administrator
Administrator
Posts: 18556
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post 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
Shannara
Addict
Addict
Posts: 1808
Joined: Thu Oct 30, 2003 11:19 pm
Location: Emerald Cove, Unformed

Post 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?
Fred
Administrator
Administrator
Posts: 18556
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Post 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.
User avatar
fsw
Addict
Addict
Posts: 1603
Joined: Tue Apr 29, 2003 9:18 pm
Location: North by Northwest

Post 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.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5709
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Post 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:
ImageThe happiness is a road...
Not a destination

PureBasic French Forum
Post Reply