2011/8/23 Johnny Rosenberg <[email protected]>: > 2011/8/20 Johnny Rosenberg <[email protected]>: >> 2011/8/19 Niklas Johansson <[email protected]>: >>> To empty the array use x = Nothing. So before the ReDim-statement do... >>> >>> … >>> x = Nothing >>> ReDim x(1) As MyType >>> … >>> >>> I think you stumbled upon a bug since your using Option Compatible it should >>> have the same behavior as VBA. In VBA both ReDim statements yields an error. >>> “ReDim x(1) As MyType” because it has already been dimensioned and ReDim y >>> As MyType because it is not a dynamic Array. >> >> Okay, thanks everyone for your input. It seems like I have >> misunderstood the concept a little bit. I'll take a closer look at it >> when I get home after the weekend. >> >> J.R. >> > > I am now at home again, so I did some more tests. Here's the current > example code (I modified the first one a little bit): > REM ***** BASIC ***** > > Option Compatible > Option Explicit > > Type MyType > a As Integer > b As Integer > End Type > Dim x() As MyType ' Comment 1a: See Comment 2 below. > Dim x(1) As MyType ' Comment 1b: See Comment 2 below. > Dim z() As Integer > > Sub Main > Dim y As MyType > Dim i As Integer > ReDim x(1) As MyType ' Comment 2: Gives an error if x was declared as > at Comment 1a, > ' and the line at Comment 1b is omitted. > ' However, if both lines (1a and 1b) are there, > there is no error. > ReDim z(3) As Integer > For i=0 To 1 > x(i).a=i*2 > x(i).b=1+i*2 > Next i > > For i=0 To 3 > z(i)=6+i > Next i > > y.a=4 > y.b=5 > > MsgBox x(0).a & x(0).b & x(1).a & x(1).b & y.a & y.b & _ > z(0) & z(1) & z(2) & z(3) ' Comment 3: Displays 12345678910 > > x=Nothing > ReDim x(1) As MyType > ReDim z(3)
Sorry, a type there. Should have been: ReDim z(3) As Integer It didn't matter for this test though. Kind regards Johnny Rosenberg ジョニー・ローゼンバーグ > ReDim y As MyType ' Comment 4: This doesn't give an error, but it > should? > MsgBox x(0).a & x(0).b & x(1).a & x(1).b & y.a & y.b & _ > z(0) & z(1) & z(2) & z(3) ' Comment 5: Displays 0000000000 > End Sub > ———End of code——— > > ”x=Nothing” seems to be the easiest solution or workaround at the > moment. The suggestion to define x as a dynamic array didn't work with > MyType. When doing ReDim, see Comment 2 within the code, I got an > error message about the index, that was out of bounds, an error > message I didn't get for z(), which I declared as Integer instead of > MyType. > It seems like I can ReDim x outside the subroutine but not inside it, > see comments 1a, 1b and 2. > > So, if I declare something as a custom data type above a subroutine or > function, I can not ReDim it inside a subroutine or function. Why is > that? Or is it a bug? Because I can do that if it's declared as one of > the existing data types, such as Integer. > > So after all, it seems like the combination of custom data types and > ReDim doesn't behave in an expected way, does it? So there is maybe a > bug there to report. > And, as already pointed out, accepting ReDim for y in my example is > probably also a bug, right? > > > > Kind regards > > Johnny Rosenberg > ジョニー・ローゼンバーグ > -- For unsubscribe instructions e-mail to: [email protected] Problems? http://www.libreoffice.org/get-help/mailing-lists/how-to-unsubscribe/ Posting guidelines + more: http://wiki.documentfoundation.org/Netiquette List archive: http://listarchives.libreoffice.org/global/users/ All messages sent to this list will be publicly archived and cannot be deleted
