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)
(earliest affected) release
Hardware: All Windows (All)
: medium normal
Assignee: Not Assigned
Depends on:
Blocks: Macro-VBA
  Show dependency treegraph
Reported: 2012-07-27 19:46 UTC by Tor24_1975314
Modified: 2020-11-10 23:27 UTC (History)
5 users (show)

See Also:
Crash report or crash signature:
Regression By:

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

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"

    ' 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!"
        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:, and
Comment 4 Tor24_1975314 2014-05-04 14:38:35 UTC
This bug was reproduced also in LibreOffice Calc version and 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!
Comment 7 Tor24_1975314 2016-06-26 14:33:11 UTC
This problem still exists and was also reproduced in LibreOffice versions,, and 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()

* 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()

* when VBASupport is 0,
"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)

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

now let's move onto SbiExprNode* SbiExpression::Like()
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 ( 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 (x86) for Windows
LibreOffice (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.