The documentation states "Instead of Else If you can write ElseIf, ..." https://help.libreoffice.org/latest/ka/text/sbasic/shared/03090101.html This seems to be untrue, see the following code where the Function CC1 using ElseIf works perfectly as expected, while CC is in a mess and should not even compile, because it as two End If Copy the code into a module and execute Main Sub Main MsgBox CC(0) MsgBox CC1(0) End Sub Function CC(lNumber As Long) As String Dim s1 As String If lNumber <= 0 Then s1 = "lNumber <= 0" Else If lNumber > 1 Then s1 = "lNumber > 1" Else s1 = "Else" End If MsgBox s1 CC = s1 End If End Function Function CC1(lNumber As Long) As String Dim s1 As String If lNumber <= 0 Then s1 = "lNumber <= 0" ElseIf lNumber > 1 Then s1 = "lNumber > 1" Else s1 = "Else" End If MsgBox s1 CC1 = s1 End Function
I guess the CC sub is working as expected. Maybe you placed the MsgBox in the wrong place (when compared to CC1). Below is your code with proper indentation: Function CC(lNumber As Long) As String Dim s1 As String If lNumber <= 0 Then s1 = "lNumber <= 0" Else If lNumber > 1 Then s1 = "lNumber > 1" Else s1 = "Else" End If MsgBox s1 CC = s1 End If End Function So if you call CC(0) it will never reach the MsgBox nor will it set any return value.
I guess what you wanted to do in CC is: Function CC(lNumber As Long) As String Dim s1 As String If lNumber <= 0 Then s1 = "lNumber <= 0" Else If lNumber > 1 Then s1 = "lNumber > 1" Else s1 = "Else" End If End If MsgBox s1 CC = s1 End Function Notice the change in the position of "End If".
(In reply to Rafael Lima from comment #1) > I guess the CC sub is working as expected. It is not about CC or CC1, but about the documentation. According to the documentation there should be no difference between Else If and ElseIf. But there is. If Else If really worked the same as ElseIf then CC should not even compile, because syntactically there is one End If too much.
(In reply to ge.huber from comment #3) > It is not about CC or CC1, but about the documentation. According to the > documentation there should be no difference between Else If and ElseIf. But > there is. If Else If really worked the same as ElseIf then CC should not > even compile, because syntactically there is one End If too much. Well if it's just that, I agree that this could be better documented. When you use "Else If" you must have and "End If" However, when "ElseIf" is used, then you don't need and "End If" to close it. I'm setting this to NEW. @Alain what are your thoughts on this one?
This is a compiler/runtime bug I noted that IF statement is not subject to specific unit tests although it is used in all tests using a primitive syntax IF .. ELSE .. https://opengrok.libreoffice.org/xref/core/basic/qa/basic_coverage/ However help page documentation can still be improved
To make this clear. I have no idea, what the intention was that Else If should work like ElseIf. So I'm totally fine, if only the documentation changes to reflect the fact, that it actually doesn't. I'm also fine, if the behavior changes, so that the documentation get's it right after all. From my experience with Bug 80731 I'm slightly in favor of leaving the compiler as is, so as not to break code which might be out there, and only changing the documentation.
My Bad, this must be considered solely as a documentation issue.
(In reply to Alain Romedenne from comment #7) > My Bad, this must be considered solely as a documentation issue. 2nd that.
Alain Romedenne committed a patch related to this issue. It has been pushed to "master": https://git.libreoffice.org/help/commit/80cfa06de7bb382c30ead55837378dcd568d2e30 tdf#161883 Fix to IF Basic statement syntax diagram