Hi!
As we know by now, in LibreOffice Basic we can not copy an array directly,
we will only get a new name for the same array. It's like assigning two
array pointers to the same array. The obvious way to copy an array is to do
it element by element in a loop, but there is a workaround. Here's an
example that works:
*Option ExplicitSub Test1 Dim A(9) As Long Dim i As Integer'
Initialise a: For i=0 To 9 A(i)=i Next i' Copy A to B:
Dim B(9) As Long: B=A ReDim Preserve B(9)' Do some changes to B
without affecting A: B(7)=A(3) B(3)=A(7)*
*' Display the results:*
* Dim Message As String, Tab As String, NL As String, Spc As String
Tab=Chr(9): NL=Chr(13): Spc=" " Message="i" & Tab & "A(i)" & Tab &
"B(i)" & NL For i=0 To 9 Message=Message & i & Tab & Spc & A(i) &
Tab & Spc & B(i) & NL Next i MsgBox MessageEnd Sub*
So, the trick in this case is to first assign B to A, then running the
ReDim statement. After that we have two separate arrays.
However, I want to do this with a custom type, like so:
*Private Type NumberType Value As Long Status As BooleanEnd Type*
*Sub Test2 Dim A(9) As NumberType Dim i As Integer' Initialise
a. For i=0 To 9 A(i).Value=i A(i).Status=True Next
i' Copy A to B Dim B(9) As NumberType: B=A ' ”Basic runtime error:
Object required.” ReDim Preserve B(9)End Sub*
This will throw a runtime error at *B=A* at third line from the end: ”Basic
runtime error: Object required”. What am I missing? How to do this properly?
Kind regards
Johnny Rosenberg