Bug 52601 - Excel Visual Basic compatibility issue in LibreOffice Calc: If Not ... Like … Then
Summary: Excel Visual Basic compatibility issue in LibreOffice Calc: If Not ... Like …...
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: LibreOffice (show other bugs)
Version:
(earliest affected)
3.5.5.3 release
Hardware: All Windows (All)
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: Macro-VBA
  Show dependency treegraph
 
Reported: 2012-07-27 19:46 UTC by Tor24_1975314
Modified: 2024-11-11 03:13 UTC (History)
5 users (show)

See Also:
Crash report or crash signature:


Attachments
Excel file with macro (38.00 KB, application/vnd.ms-excel)
2012-07-27 19:46 UTC, Tor24_1975314
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Tor24_1975314 2012-07-27 19:46:39 UTC
Created attachment 64803 [details]
Excel file with macro

In some cases Excel Visual Basic code in LibreOffice working with additional parenthesize only!

Example for "If", the following code works in Excel but not in Calc:
If Not LCase(Range("A1").Value) Like "*date*from*to*" Then

This code works in Calc:
If Not (LCase(Range("A1").Value) Like "*date*from*to*") Then

Example macro:
Sub Test_LIKE_not_ok()
    ' Preparing Test:
    Range("A2").FormulaR1C1 = "Date from 12.01.2001 to 31.12.2020"
    Range("A2").Select

    ' Testing Excel VBA Code in Libre Office:
    If Not LCase(Range("A2").Value) Like "*date*from*to*" Then
        MsgBox "Muster '*date*from*to*' not found!"
    Else
        MsgBox "Muster '*date*from*to*' found!"
    End If
End Sub
Comment 1 Tor24_1975314 2012-09-02 11:44:38 UTC
This bug occurs in LibreOffice version 3.5.6 and 3.6.1
Comment 2 Julien Nabet 2014-02-09 15:51:39 UTC
On pc Debian x86-64 with master sources updated yesterday, I can reproduce this.

Noel: put you in cc since you might be interested in this one.
Comment 3 Tor24_1975314 2014-02-18 18:35:13 UTC
This bug was also reproduced in newer versions of LibreOffice for Windows! 

Tested with LibreOffice versions: 4.0.4.2, 4.1.4.2 and 4.2.0.4
Comment 4 Tor24_1975314 2014-05-04 14:38:35 UTC
This bug was reproduced also in LibreOffice Calc version 4.2.3.3 and 4.2.4.1 rc!
Comment 5 QA Administrators 2015-06-08 14:42:11 UTC Comment hidden (obsolete)
Comment 6 Tor24_1975314 2015-06-15 21:20:48 UTC
The problem still exists!

This bug was also reproduced in LibreOffice 4.4.3.2!
Comment 7 Tor24_1975314 2016-06-26 14:33:11 UTC
This problem still exists and was also reproduced in LibreOffice versions 4.4.7.2, 5.0.4.2, 5.1.1.3 and 5.1.4.2 for Windows.

(Test system: Windows 7 64-bit, Intel Core2Duo P8700 2.53 Ghz, 4 GB RAM, Java SE Runtime Environment build 1.6.0_24-b07)
Comment 8 Xisco Faulí 2017-06-12 12:00:34 UTC
Changing version back to the earliest affected version.
Comment 9 himajin100000 2017-07-24 00:53:49 UTC
* Explanations are often easier to understand when we begin with easy lessons, even if the lessons are not directly focusing the problem I'm facing.

* To begin with, let's take a look at the following code SbiExprNode* SbiExpression::Comp()
https://opengrok.libreoffice.org/xref/core/basic/source/comp/exprtree.cxx?r=85d71244#727

* I see Cat() called in Comp(). This means string concatenation binary operator has stronger associativity
the expression a & b < c  is interpreted as ((a & b) < c) , but not as (a & (b < c))

* now let's move onto SbiExprNode* SbiExpression::Like()
https://opengrok.libreoffice.org/xref/core/basic/source/comp/exprtree.cxx?r=85d71244#727

* when VBASupport is 0,
https://opengrok.libreoffice.org/xref/core/basic/source/comp/exprtree.cxx?r=85d71244#754
"NOT" keyword is handled deeper callees inside Comp.

* when VBASupport is 1
"NOT" keyword is handled in VBA_not and there Comp is called later.

This two descriptions mean the following results from the same code.

in VBASupport 1

NOT 3 < 5 
=> (NOT (3 < 5))
=> (NOT (-1))
=> 0 

in VBASupport 0

((NOT 3) < 5)
(-4 < 5)
-1

Likewise we can say
-2^2 is (-2)^2 in VBASupport 0, VBASupport 1, and cell formulas in Calc and Excel. In MS Office VBA, the expression is -(2^2)

*in both VBASuppport 0 and in VBASupport 1
as NOT has higher associativity than LIKE, the result of the following code  is as follows

NOT "xyz" LIKE "xyz"
=>((NOT "xyz") LIKE "xyz")

but not

(NOT ("xyz" LIKE "xyz"))

Here we try to evaluate (NOT "xyz") and give up. (runtime error, not compile error)

*If the function used returns boolean or Integer, the code runs without giving runtime error.
the result of NOT operation seems to be converted to string and passed to LIKE operator's first operand.

Sub Main()
	Msgbox(NOT Foo("bar") LIKE "Meaningless sample text : - NOT 13 gives compile error when VBASupport is 1. I don't know the intention of If statement in SbiExpression::Unary()")
End Sub

Function Foo(meaninglessparameter as string) As Integer
	Foo = 1
End Function
Comment 10 himajin100000 2017-07-25 04:21:03 UTC
Oops,typo.

now let's move onto SbiExprNode* SbiExpression::Like()
https://opengrok.libreoffice.org/xref/core/basic/source/comp/exprtree.cxx?r=85d71244#771
Comment 11 Tor24_1975314 2017-11-05 20:38:47 UTC
Code tested with "Option VBASupport 1" and the newest version of LibreOffice 5.4.2 (5.4.2.2 for Windows)

Still the same problem the code:
If Not LCase(Range("A2").Value) Like "*date*from*to*" Then
[...]
End If

It works in MS Excel without any problems but not in LibreOffice!
Comment 12 QA Administrators 2018-11-06 03:55:56 UTC Comment hidden (obsolete)
Comment 13 QA Administrators 2020-11-06 04:20:08 UTC Comment hidden (obsolete)
Comment 14 Tor24_1975314 2020-11-10 23:27:36 UTC
This bug was tested again and it can be confirmed that this issue still exists.

Tested versions of LibreOffice:
LibreOffice 6.4.6.2 (x86) for Windows
and
LibreOffice 7.0.1.2 (x86) for Windows

Installed Java version:
Java(TM) SE Runtime Environment (build 1.8.0_231-b11)

This test was done using the Excel file as attached in the first bug report.
Comment 15 QA Administrators 2022-11-11 03:56:47 UTC Comment hidden (obsolete)
Comment 16 QA Administrators 2024-11-11 03:13:15 UTC
Dear Tor24_1975314,

To make sure we're focusing on the bugs that affect our users today, LibreOffice QA is asking bug reporters and confirmers to retest open, confirmed bugs which have not been touched for over a year.

There have been thousands of bug fixes and commits since anyone checked on this bug report. During that time, it's possible that the bug has been fixed, or the details of the problem have changed. We'd really appreciate your help in getting confirmation that the bug is still present.

If you have time, please do the following:

Test to see if the bug is still present with the latest version of LibreOffice from https://www.libreoffice.org/download/

If the bug is present, please leave a comment that includes the information from Help - About LibreOffice.
 
If the bug is NOT present, please set the bug's Status field to RESOLVED-WORKSFORME and leave a comment that includes the information from Help - About LibreOffice.

Please DO NOT

Update the version field
Reply via email (please reply directly on the bug tracker)
Set the bug's Status field to RESOLVED - FIXED (this status has a particular meaning that is not 
appropriate in this case)


If you want to do more to help you can test to see if your issue is a REGRESSION. To do so:
1. Download and install oldest version of LibreOffice (usually 3.3 unless your bug pertains to a feature added after 3.3) from https://downloadarchive.documentfoundation.org/libreoffice/old/

2. Test your bug
3. Leave a comment with your results.
4a. If the bug was present with 3.3 - set version to 'inherited from OOo';
4b. If the bug was not present in 3.3 - add 'regression' to keyword


Feel free to come ask questions or to say hello in our QA chat: https://web.libera.chat/?settings=#libreoffice-qa

Thank you for helping us make LibreOffice even better for everyone!

Warm Regards,
QA Team

MassPing-UntouchedBug