Issue 83143 - OOBasic: ReDim on array of user-defined type doesn't work
Summary: OOBasic: ReDim on array of user-defined type doesn't work
Status: ACCEPTED
Alias: None
Product: App Dev
Classification: Unclassified
Component: api (show other issues)
Version: 3.3.0 or older (OOo)
Hardware: All All
: P3 Trivial
Target Milestone: ---
Assignee: AOO issues mailing list
QA Contact:
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-10-31 00:03 UTC by spdfo
Modified: 2017-05-20 10:44 UTC (History)
3 users (show)

See Also:
Issue Type: DEFECT
Latest Confirmation in: ---
Developer Difficulty: ---


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description spdfo 2007-10-31 00:03:18 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
Comment 1 jsc 2007-10-31 06:46:08 UTC
jsc -> ab: seems to be one for you
Comment 2 ab 2007-11-15 13:47:38 UTC
STARTED, 3.x
Comment 3 bmarcelly 2009-02-27 19:32:00 UTC
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.
Comment 4 slowmo 2015-08-31 08:14:42 UTC
I'm on OOo version 4.1.1 and ran in this problem as well. So this issue never got fixed?
Comment 5 Marcus 2017-05-20 10:44:26 UTC
Reset the assignee to the default "issues@openoffice.apache.org".