[Libreoffice-bugs] [Bug 43490] Redim function with option base set to 1 not working correctly

bugzilla-daemon at freedesktop.org bugzilla-daemon at freedesktop.org
Mon Apr 30 11:08:15 CEST 2012


Noel Power <nopower at novell.com> changed:

           What    |Removed                     |Added
             Status|NEW                         |RESOLVED
         Resolution|                            |NOTABUG

--- Comment #3 from Noel Power <nopower at novell.com> 2012-04-30 02:08:15 PDT ---
well I think mostly the problem here is the expectation that libreoffice basic
behaves in exactly the same way as microsoft vba does. That isn't the case

ubound will return -1 for an unitialized array regardless of 'base' setting.
This is different from microsoft vba which will return 0 with a 'base' setting
of 1

array initialisation e.g. Array ( x ) initialises the array to contain x + 1
elements again regardless of the 'base' setting, again this is different to
microsoft vba which will initialise an array to contain x elements in the case
of 'base' 1. If you consider this behaviour when looking at the macro example
given then the observed behaviour can be explained. 
Unfortunately even though this behaviour is not intuitive to those familiar
with microsoft vba I would imagine this ( odd ) behaviour is already accepted
for libreoffice/openoffice basic and I can't see it could be easily changed
without some major fallout in existing legacy macros.

There is another ( little known and somewhat unofficial ) option that can help
here ( 'option compatible' ) which can help

option compatible
option base 1
Sub Main
DIM table()

msgbox ubound(table)
table = Array()


size= ubound(table )
if size < 0 then size = 0
REDIM PRESERVE table( size + 1)

size= ubound(table )
REDIM PRESERVE table( size + 1)

size= ubound(table )
REDIM PRESERVE table( size + 1)

End Sub

note: the line

if size < 0 then size = 0

if there is any bug it would be imho that ubound should return 0 for the
unitialised/empty array

Configure bugmail: https://bugs.freedesktop.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

More information about the Libreoffice-bugs mailing list