Page 1 of 1
DIM does not working correct???
Posted: Mon May 03, 2010 12:45 pm
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
Re: DIM does not working correct???
Posted: Mon May 03, 2010 3:05 pm
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 
Re: DIM does not working correct???
Posted: Mon May 03, 2010 3:13 pm
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.

Re: DIM does not working correct???
Posted: Mon May 03, 2010 3:36 pm
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
Re: DIM does not working correct???
Posted: Mon May 03, 2010 3:40 pm
by Arctic Fox
It does not occur in PB 4.41 and earlier versions.
Re: DIM does not working correct???
Posted: Mon May 03, 2010 3:52 pm
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
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.
Re: DIM does not working correct???
Posted: Mon May 03, 2010 8:12 pm
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.