Apache OpenOffice (AOO) Bugzilla – Issue 83143
OOBasic: ReDim on array of user-defined type doesn't work
Last modified: 2017-05-20 10:44:26 UTC
When trying to use ReDim on array of user-defined type, OOBasic shows error: inadmissible value or data type, index out of defined range. A workaround is to use ReDim Preserve instead. But it shouldn't be needed when there is no need to preserve the array contents. Example code: Type myType s as String i as Integer End Type Sub Main Dim a() as myType ReDim a(5) as myType ' error: inadmissible value or data type, index out of End Sub If instead of "Dim a()..." change to "Dim a(0)...", no error will be shown, but the ReDim will not work either. Also reported in ooforums: http://www.oooforum.org/forum/viewtopic.phtml?t=64888
jsc -> ab: seems to be one for you
STARTED, 3.x
There is an easy work-around : use a function to declare the array, and use variant instead of the user type. In the following example, run the macro Main: Type myType s as String i as Integer End Type Function initMyType(maxIdx As Long) As Variant Dim t(maxIdx) As myType initMyType = t End Function Sub Main Dim a As Variant a = initMyType(0) ' defining an array of 1 element a(0).s = "hello" a(0).i = 123 print a(0).i, a(0).s a = initMyType(100) ' redefining as an array of 101 elements a(100).s = "good bye" a(100).i = 456 print a(100).i, a(100).s End Sub Another advantage is that the routine Main can be in another module, or even in another library.
I'm on OOo version 4.1.1 and ran in this problem as well. So this issue never got fixed?
Reset the assignee to the default "issues@openoffice.apache.org".