Bug 54912 - BASIC: Array function forces the lower boundary for arrays as 0 in spite of option base 1
Summary: BASIC: Array function forces the lower boundary for arrays as 0 in spite of ...
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
Version:
(earliest affected)
3.6.2.1 rc
Hardware: Other All
: medium normal
Assignee: Not Assigned
URL:
Whiteboard: BSA target:7.1.0
Keywords:
Depends on:
Blocks: Macro-VBA
  Show dependency treegraph
 
Reported: 2012-09-14 09:29 UTC by pierre-yves samyn
Modified: 2020-09-01 07:34 UTC (History)
4 users (show)

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description pierre-yves samyn 2012-09-14 09:29:51 UTC
Hello

Steps to reproduce:

Run the code:

option Base 1
Sub ExampleOptionBase

Dim sVar(2) As String
msgbox LBound(sVar())
sVar = array(1,2,3)
msgbox LBound(sVar())
end sub

Expected results:  the two msgbox should display 1
Actual results: first displays 1, second displays 0

You need to use then the zero element: 
msgbox sVar(0)

This bug is old (already in OOo)
Platform: Version 3.6.2.1 (Build ID: ba822cc) & Windows 7 64bits
Regards
Pierre-Yves
Comment 1 Michel Rudelle 2013-01-22 11:52:07 UTC
I reproduce this bug:

Version 3.6.4.3 (Build ID: 2ef5aff) - Vista
Version 4.0.0.1 (Build ID: 527dba6f6e0cfbbc71bd6e7b88a52699bb48799) - Vista
Comment 2 QA Administrators 2015-02-19 15:36:11 UTC Comment hidden (obsolete)
Comment 3 pierre-yves samyn 2015-02-20 08:59:17 UTC
Hi

Still occurs on Windows 7/64 & Version: 4.4.1.1
Build ID: b5ac74bf8683a92078a2bc8aff97d4b436af63cb
Locale : fr_FR

Regards
Pierre-Yves
Comment 4 QA Administrators 2016-02-21 08:34:32 UTC Comment hidden (obsolete)
Comment 5 Michel Rudelle 2016-02-21 13:47:34 UTC
This bug is still present on both versions (OS Vista-32b):

Version: 5.0.5.2
Build ID: 55b006a02d247b5f7215fc6ea0fde844b30035b3
Locale : fr-FR (fr_FR)

Version: 5.1.0.1
Build ID: bcace328aabc4c8c10b56daa87da0a2ee6579b5a
Locale : fr-FR (fr_FR)
Comment 6 QA Administrators 2017-03-06 14:55:48 UTC Comment hidden (obsolete)
Comment 7 pierre-yves samyn 2017-03-18 06:49:10 UTC
Hi

Still reproduced on windows 7/64 & Version: 5.3.1.2
Build ID: e80a0e0fd1875e1696614d24c32df0f95f03deb2
CPU Threads: 2; OS Version: Windows 6.1; UI Render: default; Layout Engine: new; 
Locale: fr-FR (fr_FR); Calc: group

Regards
Pierre-Yves
Comment 8 QA Administrators 2018-03-19 03:33:49 UTC Comment hidden (obsolete)
Comment 9 pierre-yves samyn 2018-03-19 08:22:56 UTC
Hi

Still occurs on Windows 7/64 with Version: 6.0.2.1 (x64)
Build ID: f7f06a8f319e4b62f9bc5095aa112a65d2f3ac89
CPU threads: 2; OS: Windows 6.1; UI render: default; 
Locale: fr-FR (fr_FR); Calc: group

Regards
Pierre-Yves
Comment 10 QA Administrators 2019-05-23 02:49:58 UTC Comment hidden (obsolete)
Comment 12 Andreas Heinisch 2020-08-17 14:14:35 UTC
I investigated the error and it seems that Option VBASupport must set to 1 in order to set the lower bound of an array to 1. Should we accept only Option Base 1 without Option VBASupport in order to set the starting index of an array to 1?
Comment 13 Andreas Heinisch 2020-08-25 09:20:16 UTC
After some investigation, here are my findings. Consider the following code snippet:

Sub Main()

Dim strArray(2) As String

MsgBox LBound(strArray)
MsgBox UBound(strArray)
MsgBox UBound(strArray, 1) - LBound(strArray, 1) + 1

Redim strArray(3)
MsgBox LBound(strArray)
MsgBox UBound(strArray)
MsgBox UBound(strArray, 1) - LBound(strArray, 1) + 1

End Sub

Without any option:
    - the array starts at 0 and ends at 2 with 3 elements.
    - after the redim the array starts at 0 and ends at 3 with 4 elements.
    
With option base 1:
    - the array starts at 1 and ends at 3 with 3 elements, since this option increases also the upper bound (see #109275 in  https://jezzper.com/jezzper/discussions.nsf/0/3C030B7CC3F24D5FC1256F65002BC1B5)
    - after the redim the array starts at 1 and ends at 4 with 4 elements.
    
With option base 1 and option compatible:
    - the array starts at 1 and ends at 2 with 2 elements, since option compatible does not change the upper bound
    - after the redim the array starts at 1 and ends at 3 with 3 elements.
    
At the moment, the option base is not fully implemented and works only with the additional VBASupport option.
Comment 14 Commit Notification 2020-09-01 07:29:12 UTC
Andreas Heinisch committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/40031dd453991b3397f02726bd83cc857bef1044

tdf#54912 - with option base arrays should start at index 1

It will be available in 7.1.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.