Bug 154166 - MID statement non VBA-conformant
Summary: MID statement non VBA-conformant
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
Version:
(earliest affected)
Inherited From OOo
Hardware: All All
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: Macro-VBA Macro-StarBasic
  Show dependency treegraph
 
Reported: 2023-03-13 16:41 UTC by Alain Romedenne
Modified: 2024-08-02 15:05 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 Alain Romedenne 2023-03-13 16:41:52 UTC
Description:
Mid statement should behave as documented by MS

Steps to Reproduce:
1. open MS doc at https://learn.microsoft.com/en-us/office/vba/Language/Reference/user-interface-help/mid-statement
2. Paste the example code that details the expected outputs
3. Run the example in LibreOffice

Actual Results:
they differ from MS documentation

Expected Results:
see MS documentation


Reproducible: Always


User Profile Reset: No

Additional Info:
Current help does not document MID as a statement. Regressions are not expected to be detected.
Comment 1 Alain Romedenne 2023-03-13 16:46:15 UTC
MID is both available as a statement and as a function.
Comment 2 Rafael Lima 2023-03-14 12:43:21 UTC Comment hidden (obsolete)
Comment 3 Rafael Lima 2023-03-14 14:54:45 UTC
Forget about my Comment #2 above. I tested it wrong.

Now I ran the following code:

Sub TestMid
    Dim MyString 
    MyString = "The dog jumps" ' Initialize string. 
    Mid(MyString, 5, 3) = "fox"
    MsgBox MyString
    Mid(MyString, 5) = "cow"
    MsgBox MyString
    Mid(MyString, 5) = "cow jumped over" ' MyString = 
    MsgBox MyString
    Mid(MyString, 5, 3) = "duck" ' MyString = 
    MsgBox MyString
End Sub

In MS VBA we get:
"The fox jumps"
"The cow jumps"
"The cow jumpe"
"The duc jumpe"

In LO Basic we get:
"The fox jumps"
"The cow"
"The cow"
"The duc"

It seems that when you omit the "Length" argument, LO Basic cuts off the remainder of the string.

Also, when the resulting string is larger than the original string, MS VBA cuts off the difference and keeps the string length, whereas LO Basic increases the string length.

So yeah, I believe they both should work the same way.
Comment 4 Alain Romedenne 2024-08-02 15:05:35 UTC
Named/Keyword arguments should be documented according to line 595 in https://opengrok.libreoffice.org/xref/core/basic/source/runtime/stdobj.cxx?r=98f88ac1 until VBA compatibility is implemented.

cf. Positional or Keyword Arguments in https://help.libreoffice.org/24.2/en-US/text/sbasic/shared/01020300.html?&DbPAR=SHARED&System=UNIX