Consider the code: Option Compatible sub foo(Optional v As Variant = Empty) MsgBox v end sub sub bar foo end sub In MS Office (Word/Excel, indeed omitting the 'Option Compatible', which is LibreOffice Basic compatibility flag), when running bar, it shows an empty message. In LibreOffice, this code doesn't compile, giving syntax error on the 'Empty' default argument value; the same happens with 'Option VBASupport 1'. Replacing the 'Empty' with other values, like '1' or '""', succeeds. There is no reason why the 'Empty' shouldn't work here.
Repro in: Version: 7.6.1.2 (X86_64) / LibreOffice Community Build ID: f5defcebd022c5bc36bbb79be232cb6926d8f674 CPU threads: 16; OS: Windows 10.0 Build 22631; UI render: Skia/Raster; VCL: win Locale: en-GB (de_DE); UI: en-GB Calc: CL threaded
Consider next code: sub foo(Optional a, Optional b) MsgBox IsEmpty(a) end sub sub bar foo(b := 1) end sub - (1) The message box returns True without any option, or with Option Compatible - (2) A syntax error is displayed with Option VBASupport 1 In other words when (1) and the call uses the := syntax, the skipped arguments contain Empty, not "Missing". Empty means something in this matter. That's the reason why in ScriptForge, everywhere I test the presence of an argument to set a default value (hundredths of times ...) I use the construction If IsMissing(a) Or IsEmpty(a) Then a = ... Please do not change the actual behaviour without good reasons.
(In reply to Jean-Pierre Ledure from comment #2) > Please do not change the actual behaviour without good reasons. Which change is meant?
(In reply to Mike Kaganski from comment #3) > Which change is meant? Well, a potential patch that would implement Empty as being a valid default value. This could create a conflict with Empty meaning missing in some cases in existing scripts.
(In reply to Jean-Pierre Ledure from comment #2) > - (1) The message box returns True without any option, or with Option > Compatible > - (2) A syntax error is displayed with Option VBASupport 1 > > In other words when (1) and the call uses the := syntax, the skipped > arguments contain Empty, not "Missing". Empty means something in this matter. This is a bug. It must be fixed. It is orthogonal to this issue. (In reply to Jean-Pierre Ledure from comment #4) > a potential patch that would implement Empty as being a valid default > value. > This could create a conflict with Empty meaning missing in some cases in > existing scripts. This is not a reason to keep the two bugs.
I'd say the problem is not only the inability to use Empty as a default argument, but also that the interpreter assumes that an argument is Empty in a peculiar manner. Consider the following code: sub foo2(Optional v As Variant) MsgBox IsEmpty(v) MsgBox IsMissing(v) end sub sub bar2 foo2 end sub This will return False and True which to me is the expected behavior. However, the following code: sub foo3(Optional v As Variant, Optional text As String) MsgBox IsEmpty(v) MsgBox IsMissing(v) end sub sub bar3 foo3(text := "dummy") end sub ... will return True and False, which is the opposite of what I would expect, since "v" is missing and it was not defined as Empty. See bug 143706 (already referred here). I guess we need to fix bug 143706 alongside with this one to have a coherent behavior.