Issue 91693 - "If Not r Is Nothing Then" causes error '91' Object variable not set
Summary: "If Not r Is Nothing Then" causes error '91' Object variable not set
Status: CLOSED FIXED
Alias: None
Product: App Dev
Classification: Unclassified
Component: scripting (show other issues)
Version: 3.3.0 or older (OOo)
Hardware: All All
: P3 Trivial
Target Milestone: ---
Assignee: pflin
QA Contact: Unknown
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-07-16 07:52 UTC by pflin
Modified: 2013-02-24 21:00 UTC (History)
4 users (show)

See Also:
Issue Type: PATCH
Latest Confirmation in: ---
Developer Difficulty: ---


Attachments
Test document for demonstating this issue (36.50 KB, text/plain)
2008-07-16 07:54 UTC, pflin
no flags Details
a patch fixed for this issue (548 bytes, text/plain)
2008-07-16 07:55 UTC, pflin
no flags Details
update the patch so that only working in vba-compatibility. (577 bytes, text/plain)
2008-07-21 02:54 UTC, pflin
no flags Details
Problem with the class 'Range' (45.37 KB, text/plain)
2009-04-04 19:29 UTC, vladimir_hitekschool
no flags Details
Poblem with 'Range' method. (51.46 KB, text/plain)
2009-04-04 19:34 UTC, vladimir_hitekschool
no flags Details
Incompability problem (46.68 KB, text/plain)
2009-04-04 19:35 UTC, vladimir_hitekschool
no flags Details
Bypassing incompability... (26.76 KB, text/plain)
2009-04-04 19:37 UTC, vladimir_hitekschool
no flags Details

Note You need to log in before you can comment on or make changes to this issue.
Description pflin 2008-07-16 07:52:55 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
Comment 1 pflin 2008-07-16 07:54:04 UTC
Created attachment 55143 [details]
Test document for demonstating this issue
Comment 2 pflin 2008-07-16 07:55:39 UTC
Created attachment 55144 [details]
a patch fixed for this issue
Comment 3 pflin 2008-07-16 07:58:57 UTC
Andreas, please have a look at this patch. I am new to basic parser. :-)
Comment 4 bmarcelly 2008-07-17 13:13:49 UTC
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.
Comment 5 pflin 2008-07-18 03:24:24 UTC
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.
Comment 6 bmarcelly 2008-07-18 10:57:44 UTC
<< 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.
Comment 7 pflin 2008-07-21 02:54:31 UTC
Created attachment 55245 [details]
update the patch so that only working in vba-compatibility.
Comment 8 noel.power 2008-07-22 07:30:32 UTC
>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 
Comment 9 ab 2008-08-29 15:04:36 UTC
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)
Comment 10 pflin 2008-09-01 10:37:36 UTC
added into cws pflin10
Comment 11 kenyu 2008-09-22 08:19:05 UTC
Verified
Comment 12 kenyu 2008-10-13 07:25:14 UTC
Verified
Comment 13 vladimir_hitekschool 2009-04-04 19:27:41 UTC
 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).
Comment 14 vladimir_hitekschool 2009-04-04 19:29:16 UTC
Created attachment 61388 [details]
Problem with the class 'Range'
Comment 15 vladimir_hitekschool 2009-04-04 19:34:12 UTC
Created attachment 61389 [details]
Poblem with 'Range' method.
Comment 16 vladimir_hitekschool 2009-04-04 19:35:58 UTC
Created attachment 61390 [details]
Incompability problem
Comment 17 vladimir_hitekschool 2009-04-04 19:37:31 UTC
Created attachment 61391 [details]
Bypassing incompability...
Comment 18 vladimir_hitekschool 2009-04-04 19:41:14 UTC
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.
Comment 19 noel.power 2009-04-07 11:49:58 UTC
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 )
Comment 20 thorsten.ziehm 2010-02-22 15:43:46 UTC
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