Apache OpenOffice (AOO) Bugzilla – Issue 91693
"If Not r Is Nothing Then" causes error '91' Object variable not set
Last modified: 2013-02-24 21:00:32 UTC
The following macro can reproduce this issue: Sub test_nothing() Dim r As Range 'Set r = Range("A1") 'Set r = Nothing If Not r Is Nothing Then 'causes error MsgBox "OK" Else MsgBox "Fail" End If End Sub But If Not (r Is Nothing) Then can works
Created attachment 55143 [details] Test document for demonstating this issue
Created attachment 55144 [details] a patch fixed for this issue
Andreas, please have a look at this patch. I am new to basic parser. :-)
IMHO this is not a bug and this Issue should be rejected. Unary operator NOT applies to the next argument which is variable r. This results in a boolean value, which of course is not an object, so the error message. Your patch will probably give to operator IS a higher priority than to operator NOT. Giving to a binary operator a priority higher than to a unary operator would be contrary to usual rules.
pflin -> bmarcelly, thanks for your quick respond. >IMHO this is not a bug and this Issue should be rejected. The statement "If Not r Is Nothing Then" is common to use in MS Office, and can work in MSO, but fail to work in OOo Basic. IMHO it would be better if the statement can work in OOo basic too. > Your patch will probably give to operator IS a higher priority than to operator NOT. For my test, the statement "If (Not r) Is Nothing Then" will cause error in MSO if r is a object variable. So in this case, I think 1) Unary operator NOT applies to the next argument which is a object variable r, will cause error. 2) operator IS should be a higher priority than to operator NOT, so the statement "If Not r Is Nothing Then" can work > Giving to a binary operator a priority higher than to a unary operator would be contrary to usual rules. I don't expect to break the usual rules. But for this case, it need to process specially.
<< The statement "If Not r Is Nothing Then" is common to use in MS Office, and can work in MSO, but fail to work in OOo Basic. >> If you want to copy VBA bugs, then your patch should only work in VBA-compatible mode, just to be sure that pure OOoBasic works as usual. Because "Is" and "Nothing" are already usable in OOoBasic.
Created attachment 55245 [details] update the patch so that only working in vba-compatibility.
>IMHO this is not a bug and this Issue should be rejected. >Unary operator NOT applies to the next argument which is variable r I don't agree, actually both the MSO and Openoffice.org help agree that Not-Operator syntax is as follows Result = Not Expression ^^^^^^^^^^ so imo this *is* a valid bug fixing incorrect behaviour. But... as always, caution is a good thing ;-) and making this a vba only option ( initially ) is not such a bad idea until Andreas casts his deciding vote
I vote for the vba-compatibility only version. Noel will be very surprised... ;-) In general the patch seems to be ok, only one small issue in token.hxx: ~SbiTokenizer(); has to become virtual ~SbiTokenizer(); because otherwise the Windows Compiler gives a warning (a virtual method has been added and then it wants also the dtor to be virtual)
added into cws pflin10
Verified
As to issue 91693 there are still problems with the vba-compatibility. Class 'Range' possibly has not been defined in object library in OOo-dev Basic, so we have Basic syntax errors (see attachments 1 & 2). But even bypassing tis restriction, we still have inconpability problem: "If Not r Is Nothing Then" causes error, but "If Not (r Is Nothing) Then" - doesn't (see attachments 3 & 4).
Created attachment 61388 [details] Problem with the class 'Range'
Created attachment 61389 [details] Poblem with 'Range' method.
Created attachment 61390 [details] Incompability problem
Created attachment 61391 [details] Bypassing incompability...
Sorry, I have forgotten to say that all was verified in in master version OOo- dev 3.1 .0 (OOO310m8 Build:9395) for Windows XP.
I am struggling to understand the corrolation between the images attached and any concerns raised. But I'll attempt to do that. Before doing that though I would say that it pays to actually run the test document, unfortunately the test document is a little misleading, you press the button and it says fail. It doesn't seem to be pointed out anywhere that this is the expected result. If you then modify the macro code and uncomment the line 'Set rg = Range("A1") you will get "True" result these are the expected results and reflect what happens when you run the same example and do the same steps in Excel. so, back to the images i91693_1.jpg: looks like a macro run in non vba compatibility mode trying to define a variable as the Range type. But.. without vba compatibility it knows nothing about the range object, that would be the expected result i91693_2.jpg: is this not the same thing, attempting to access the Range object? again this fails as expected i91693_3.jpg: this is what the bug is about right? that line causes an error in "NON" vba mode, and afaic the macros here are running in "NON" vba mode and still cause the same error, again expected result i91693_4.jpg: I can't actually work out what this is about, it just seems like the same picture as before. it seems to me you are confused about compatibility, vba mode really only works when running macros imported from an xl documents, there is the 'Option VBASupport 1' directive that you can use to trigger that mode, but you mileage may vary when using that ( especially in non document basic or non xl documents )
This issue is closed automatically. It should be fixed in a version with is available for longer than half a year (OOo 3.1). If you think this issue isn't fixed in the current version (OOo 3.2) please reopen it. But then please pay attention about the field 'target milestone'. The closure was approved by the Release Status Meeting at 22nd of February 2010 and it is based on the issue handling guideline for fixed/verified issues : http://wiki.services.openoffice.org/wiki/Handle_fixed_verified_issues