2011/8/18 planas <jsloz...@gmail.com>:
> Johnny,
>
> On Thu, 2011-08-18 at 18:11 +0200, Johnny Rosenberg wrote:
>
>> I was, in a reply to another question, told that my questions were way
>> too basic for the d...@api.openoffice.org list, so I'll give it a try
>> here instead.
>>
>> I wrote some example code:
>>
>> REM  *****  BASIC  *****
>>
>> Option Compatible
>> Option Explicit
>>
>> Type MyType
>>        a As Integer
>>        b As Integer
>> End Type
>> Dim x(1) As MyType
>>
>> Sub Main
>>        Dim y As MyType
>>        Dim i As Integer
>>        For i=0 To 1
>>                x(i).a=1+i*2
>>                x(i).b=2+i*2
>>        Next i
>>        y.a=5
>>        y.b=6
>>
>>        MsgBox x(0).a & x(0).b & x(1).a & x(1).b & y.a & y.b ' Displays 123456
>>
>>        ReDim x(1) As MyType
>>        ReDim y As MyType
>>        MsgBox x(0).a & x(0).b & x(1).a & x(1).b & y.a & y.b ' Displays 123400
>> End Sub
>>
>> So if we have an array as MyType (or any other custom type, I
>> suppose), ReDim will not reset it.
>> Is this the expected behaviour or should I write a bug report?
>> If it is expected, why?
>>
>> I guess it's unnecessary to mention that I am a complete beginner in
>> everything that has anything to do with computers; we guitar players
>> are quite stupid, you know.
>>
>> Oh, and in case it matters:
>> LibreOffice 3.3.3, Ubuntu 10.10.
>> LibreOffice installed with the debs at http://www.libreoffice.org/.
>>
>> Best regards
>>
>> Johnny ”The Moron” Rosenberg
>> ジョニー・ローゼンバーグ
>>
>
> I had to look up ReDim behavior myself, so do not to hard on yourself.
> ReDim is used to re-dimension an array. It is particular useful when you
> are likely to encounter an variable length array (different length each
> time the code executes). Normally when the array is re-dimensioned the
> previous values are destroyed because you normally want to enter new
> values into the array. Some flavors of basic allow to use ReDim Preserve
> to preserve the array's original value - you may want to try this to see
> if works.

No, Preserve does the opposite, it preserves all the values. I want an
EMPTY array without having to empty them with a time consuming For
loop, so I though ReDim should do the job very quickly. It does in
most cases, but as my example shows, not always…

As you can see in my example, after ReDim y is reset to 0 (y.a=0,
y.b=0) but x is not (x(0).a=1, for example). The difference between x
and y is that x is an array and x is declared above the subroutine
(this was a couple of days ago, so I don't remember if I tested
absolutely everything, but as far as I remember, my conclusion was
that an array of a custom type isn't reset to 0 after ReDim, I am not
sure if there was a difference if it was defined in a subroutine or
outside.

So my question still is: Is this what I should expect or is it a bug?
If it is a bug I will need to write a bug report, won't I? But I don't
want to do that if this is the expected behaviour, because it only
annoys people…


Kind regards

Johnny Rosenberg
ジョニー・ローゼンバーグ

>
> A common use is
> Dim MyArray() as type
>
> ReDim MyArry(1 to x), x will be supplied by the procedure.
>
> Often there are little subtleties that can drive you crazy when program,
> the compiler/interpreter is very fussy that you follow all the grammar
> and syntax rules for the langauge.
> --
> Jay Lozier
> jsloz...@gmail.com
>
> --
> For unsubscribe instructions e-mail to: users+h...@global.libreoffice.org
> 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
>

-- 
For unsubscribe instructions e-mail to: users+h...@global.libreoffice.org
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

Reply via email to