DIM does not working correct???

Just starting out? Need help? Post your questions and find answers here.
walker
Enthusiast
Enthusiast
Posts: 634
Joined: Wed May 05, 2004 4:04 pm
Location: Germany

DIM does not working correct???

Post by walker »

before reporting as a bug ... and maybe it's only my stupid way to do things ... :roll:

is this worth a bug report or did I overlook something?
i guess dim does not work correct....
(step trough with debugger and have a look at the array dimensions)

Code: Select all

Dim array_1.s(1, 10)
Dim array_2.s(0, 0)
;create some content
For x = 1 To 10
    array_1(1, x) = Chr(60 + x)
Next

rows = 1
cols = 10

For m = 1 To 2
    nrows = rows
    ncols = cols
    Dim array_2.s(0, 0); set content to nothing
    Dim array_2.s(nrows, ncols)
    Swap array_1(), array_2()

    Debug array_2(1, m)

    Dim array_1.s(0, 0)
    Dim array_1.s(nrows, ncols)
    Swap array_2(), array_1(); now array_1 should contain the original content .. but is set to -1,-1 ....
    rows = nrows
    cols = ncols
Next
User avatar
Rook Zimbabwe
Addict
Addict
Posts: 4322
Joined: Tue Jan 02, 2007 8:16 pm
Location: Cypress TX
Contact:

Re: DIM does not working correct???

Post by Rook Zimbabwe »

Why not use ReDim???

Code: Select all

Dim array_1.s(1, 10)
Dim array_2.s(0, 0)
;create some content
For x = 1 To 10
    array_1(1, x) = Chr(60 + x)
Next

Debug "Array_1 = "+array_1(1, 0)
Debug "Array_1 = "+array_1(1, 1)
Debug "Array_1 = "+array_1(1, 2)

rows = 1
cols = 10

For m = 0 To 2
    nrows = rows
    ncols = cols
    Dim array_2.s(0, 0); set content to nothing
    Dim array_2.s(nrows, ncols)
    Swap array_1(), array_2()

    Debug "Array_2 = "+array_2(1, m)

    ; Dim array_1.s(0, 0) ; cannot understand why you just didn't use ReDim
    ReDim array_1.s(nrows, ncols)
    Swap array_2(), array_1(); now array_1 should contain the original content .. but is set to -1,-1 ....
    rows = nrows
    cols = ncols
Next
End
I don't see the issue if you use redim... that would clean the array

You cannot set an array to less than 1 is the only thing I can think of so use ReDim :mrgreen:
Binarily speaking... it takes 10 to Tango!!!

Image
http://www.bluemesapc.com/
User avatar
Arctic Fox
Enthusiast
Enthusiast
Posts: 609
Joined: Sun Dec 21, 2008 5:02 pm
Location: Aarhus, Denmark

Re: DIM does not working correct???

Post by Arctic Fox »

Rook Zimbabwe wrote:Why not use ReDim???
PB Help wrote:If ReDim is used with a multi-dimension array, only its last dimension can be changed.
:wink:
Trond
Always Here
Always Here
Posts: 7446
Joined: Mon Sep 22, 2003 6:45 pm
Location: Norway

Re: DIM does not working correct???

Post by Trond »

I have a feeling it's more related tothe swap than the dim.

Code: Select all

Dim array_1.s(1)
Dim array_2.s(1)

Swap array_1(), array_2()
Dim  array_1(1)
CallDebugger
User avatar
Arctic Fox
Enthusiast
Enthusiast
Posts: 609
Joined: Sun Dec 21, 2008 5:02 pm
Location: Aarhus, Denmark

Re: DIM does not working correct???

Post by Arctic Fox »

It does not occur in PB 4.41 and earlier versions.
walker
Enthusiast
Enthusiast
Posts: 634
Joined: Wed May 05, 2004 4:04 pm
Location: Germany

Re: DIM does not working correct???

Post by walker »

@artic yes.. thats one of the reasons why i do not used redim
the other reason is , that this is stripped out of a working code from a time, redim doesnt worked at all :shock:
I tried to recompile an application which was written with pb 4.00 - pb 4.20

and why should I not swap content of 2 arrays in that way? its to preserve the content while manipulating the array... so i could do a rollback ...

@trond if you set a breakpoint on the line with the dim statement ... the content and dimensions of the arrays are correct ... after calling the dim ... the dimension is set to -1

assuming that it's a bug .. i'll report it.
User avatar
Demivec
Addict
Addict
Posts: 4266
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: DIM does not working correct???

Post by Demivec »

Fred already responded to the bug report here, that using swap this way is not be supported (even though it was in the help file and worked in earlier versions).

Fred also responded to bug reports regarding Redim here.
Post Reply