"BASIC runtime error. Argument is not optional"

I tried to create my first macro in libreoffice calc, but appears error unsolvable:

Function JTMSplit2(expression1, delimiter1 , limit1)

        JTMSplit2 = Split(expression1, delimiter1, limit1)

End Function
BASIC runtime error.
Argument is not optional.

Any suggestion?

Version: 7.6.2.1 (X86_64) / LibreOffice Community
Build ID: 56f7684011345957bbf33a7ee678afaf4d2ba333
CPU threads: 12; OS: Windows 10.0 Build 22621; UI render: Skia/Raster; VCL: win
Locale: es-PE (es_PE); UI: en-US
Calc: threaded

And how do you invoke the function? Obviously you can’t run it by just hitting F5 as then there are no arguments passed for the parameters…

You could enter this in the spreadsheet document at which you created the BASIC function:
=JTMSPLIT2(A1;A2;A3)
and fill A1:A3 with meaningful values.
Or rather, first enter the values and then the formula and close with Ctrl+Enter to create an array formula and display the array returned.

1 Like

And how do you invoke the function? Obviously you can’t run it by just hitting F5 as then there are no arguments passed for the parameters…

I tried to use it in cell and debugging, in both same result.

image

here a file to test.

test01 jtmsplit.ods (10.2 KB)

You have to pass exactly 3 arguments.
Or declare the function with Optional parameters to mimick the BASIC Split() function.
Function JTMSplit2(expression1, Optional delimiter1, Optional limit1)

1 Like

I did not noticed, but now I received unexpected result:

image

in vba excel this return array, but here return entire line.

Because you limit it to return only one element, with third argument 1

1 Like

If I type 0, 1, 2 or 3 should return the index, but when I use 1, 2, o 3 return the entire string.

I just found that ctrl+ shift + enter make it array result, thanks a lot for the the help.