https://bugs.documentfoundation.org/show_bug.cgi?id=91328

            Bug ID: 91328
           Summary: "Object Variable Not Set" Error Message when Member
                    not Defined for Variant
           Product: LibreOffice
           Version: 4.1.2.3 release
          Hardware: x86-64 (AMD64)
                OS: Linux (All)
            Status: UNCONFIRMED
          Severity: trivial
          Priority: medium
         Component: BASIC
          Assignee: [email protected]
          Reporter: [email protected]

Before I begin describing the bug, I'll be honest and admit that my native
programming language is C++. I haven't learnt BASIC properly, I don't have any
proper experience in it and honestly I'm not a huge fan of it, at least, not
from what I've seen so far. However in spite of my bias and naïvety, I was only
trying to write a very basic function and I still think this can be considered
a valid problem that would help programmers of all sorts if it were fixed.

I have distilled the problem to the following very basic program:


Sub TestVariant(Arg1)
    msgbox("typename", TypeName(Arg1), "is numeric", Arg1.IsNumeric())
End Sub

sub Main
        Dim int As Integer, var As Variant
      var = 4
      int = 4

     TestVariant(4)   'The program will stop upon the first of these 
    TestVariant(int) 'three calls. If the order is changed, it will
     TestVariant(var) 'happen for each one ie the error occurs equally
                         'passing a constant, an integer, and  a variant
                         'as a variant
End Sub

The error with my code is that IsNumeric is not a member function of Variant
(actually does it have any member functions at all?); I should have used the
global function isNumeric() but as I didn't come across this online I instead
found the VB equivalent. However the error message that is shown is "Object
variable not set". I have found very little information about this error
online, so I would presume that the problem is what it says on the tin, that a
variable is not set. 

The debugger produces the message when stepping into the function and so stops
on the line of the sub and argument declaration. Looking in the watches window,
currently when I reproduce the situation the type of Arg1 is Object and the
value is Null, however I am sure that when I have encountered it in the past
the type was Variant/Empty. The error message, the null value and the error
message therefore led me to believe that there was an error in passing the
arguments into the function and converting them to variants, so I modified the
argument lists to no avail. It was only when I found the e-book 'Useful Macro
Information for OpenOffice.org' by Andrew Pitonyak that I got the idea that the
problem might not be with the value itself but with the member functions.

Distilling the problem even further, the following produces the same error
message, although the debugger stops on the line with the function call, and
the value and type of the variant are displayed correctly in the watchlist:

Sub Main
        dim V as Variant
        V = 5
        V.octocats()
End Sub

Compare this to the behaviour with the following code:

Sub Main
    dim oCurrentSelection as Variant
    oCurrentSelection = ThisComponent.getCurrentSelection()
    oCurrentSelection.octocats()
End Sub


The message output is "Property or method not found:octocats", the value is
displayed correctly in the watchlist and the debugger stops on the line of the
function call.



In summary, below is what I see and what it implies to me about the cause of
the error:

    :: "Object variable not set" -> The problem is with the initial setting of
the variant to a valid value and not with what I do with the variant
afterwards.
    :: When calling a sub, the debugger stops on the argument list -> The
argument hasn't been passed correctly; the problem is with the argument list,
e.g. specifying values where references should have been used, or the caller
can't convert the given argument to a variant, or something along those lines.
    :: When calling a sub, the watch for the variant sometimes shows the type
as object -> The variant hasn't been initialised properly, similar to the above
    :: When calling a sub, the watch for the variant shows the value as null ->
As above, the variant was never initialised properly and the problem is in
passing the arguments, where this initialisation occurs

Below is what I believe should happen:

    :: At least, the message should state either something like "Property or
method not found: IsNumeric" or "Variant does not support member access" or if
the member operator is being "redirected" to an object being stored in the
variant "Variant value is not of type Object"
    :: When calling a sub, the debugger should stop on the offending line in
the function body rather than on the sub's stub.
    :: If possible, the value and type of the variant should be displayed as
they would be if the offending statement were removed, up until the offending
statement, i.e. the value is shown correctly before accessing an invalid
member.

I can try reproducing this in a newer version of LO however I'm posting this
before I replace the package in case I break my package manager in doing so. It
shouldn't happen but before when I've upgraded a package apt has asked me to
upgrade all the dependencies because the package was compiled with those, which
realistically won't have broken compatibility between minor version numbers,
such as the C runtime library.

My OS is Linux Mint Petra AMD64

-- 
You are receiving this mail because:
You are the assignee for the bug.
_______________________________________________
Libreoffice-bugs mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/libreoffice-bugs

Reply via email to