If option base is set to 1, the redim function make wrong calculation of new table size, as in following example: OPTION BASE 1 Sub Main DIM table() AS VARIANT DIM size AS INTEGER size= ubound(table ) REDIM PRESERVE table( size + 1) size= ubound(table ) REDIM PRESERVE table( size + 1) size= ubound(table ) REDIM PRESERVE table( size + 1) End Sub During tracing of this program, to size of the table is changing: 1 -> 3 -> 5 And should be changing: 1 -> 2 -> 3
Thanks for bugreport reproduced in 3.3.4 and 3.5.2 on Fedora 64 bit Variable "size" becomes -1 first time and increases by 2 in each redim statement
@ Noel What do You think about this bug?
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() DIM size AS INTEGER 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
Thanks for explanations and for reminder about 'option compatible' It will seriously help using Basic May be this option may set globally for all documents? Somewhere in Tools->Options.
Yes. I think that is exactly what OP was asking for. Thanks for taking this on.
thanks https://creditcardsupportx.com/qvc-credit-card https://creditcardsupportx.com/sams-club-credit-card https://creditcardsupportx.com/cabelas-credit-card