Cannot open Calc file, getting "BASIC runtime error." continual loop

Using an example Calc spreadsheet from “Engineering and SI Number Format in Calc” webpage. Specifically this file: https://wiki.openoffice.org/wiki/File:EngSIFormula.ods

This file used to open correctly and work but now when I try to open it I get a “BASIC runtime error.” and am forced to kill the program because I cannot get out of this error loop.

The code line being “the culprit” seems to be

  If ((Not (IsMissing (Extra))) And (Extra > 0) And (R > 0.001) And (R < 1000.0)) Then 

The example you pointed to was last modified 2009-09-16, 17:09:05.
At that time nearly 16 years ago OO.o Basic came with a “shorthand evaluation” of logical expressions which would exit the evaluation of that line as soon as the test for
Not (IsMissing (Extra)) came out false for the actually missing parameter.
The comparison Extra>0 would therefore never be touched in case of a missing Extra
This can’t work if the conjunction is executed completely in every case, and recent LibO Basic does it this way.
You may play with

Function ident(p)
ident = p
End Function

Sub testIt()
answer = (ident(2)<ident(1)) AND (ident(5)>ident(4))
Print answer
End Sub

Despite the fact that 2<1 is false, and the AND-expression can’t come out true therefore, the second parenthesis is evalueted. Execute the Sub stepwise, and you will see.

Forget the code you found.
(However, AOO 4.1 does it still the old way.)
[The code also contains a misleading usage of the predefined name EXP re-defining it implicitly.]

:slight_smile: not exactly. Basic never had any short circuiting, and still processed that other check; just didn’t error out (which was fixed in commit e32d864dbe086d630a8b17c2d376e320aee0253a).

Check this code:

Sub foo(Optional x As Variant)
  If Not (IsMissing(x)) And MsgBox("Show anyway!") <> 1000 Then MsgBox("Check succeeded")
End Sub

It will display “Show anyway!”, even though x is missing; of course, pressing OK would make MsgBox return 1, which is not 1000, so the second check is true - but the “Check succeeded” will not appear, unless you call foo passing an x.

1 Like

Thanks for the clarification!
BTW: Am I also wrong with my assumption that C does the “short circuiting”?
I faintly remember code testing points for being inside a polygon which depended on that behaviour.

Yes; for C and C++, short circuiting is the language guarantee, part of the specification.

There is a table for programming languages ​​here.

that is not “endless” loop; it only shows that for each cell having the faulty code. And there are many such cells; so you can e.g. press and hold Esc and wait a minute.

The code there is really faulty: tdf#149959.

IMHO, the problem with that file is how Basic evaluates boolean logic.

If A and B then
   x = 1
End If

If A is False, B is evaluated anyway.
Therefore, If not IsMissing(A) And (A>0) raises the not-optional-error and needs to be changed to

If not IsMissing(A) Then
    if (A>0) then
        do_stuff
    end if
end if

This is a working version of that file:
EngSIFormula_LO.ods (37.3 KB)

1 Like

Exactly. That is discussed also in tdf#153142.

1 Like