My OOo Basic macros include a lot of functions that I wrote to get text from standard ASCII text files and embedded text in binaries via "open ... for binary", but also need to handle text in OOo Writer documents as objects. In this case and in many other cases, such as sort functions that deal with objects as well as primitives, and functions that insert strings in a document alongside text content objects, I thought it was reasonable to pass the object or primitive to the procedure in question using a variant parameter, e.g.
Code: Select all
Sub inSort(anElement as variant, aList as object)
...
Dim anIndex as Long
anIndex = sortIndex(anElement)
...
End Sub
Function sortIndex(anElement as variant) as Long
If isObject(anElement) then
sortIndex = anElement.sortIndex
elseif isNumeric(anElement) then
sortIndex = anElement
else
sortIndex = len(anElement)
Endif
End Function
This works just fine when I give it an object variable (with a sortIndex property, of course), but I get an 'Object variable not set' error when I give it any other type. The error occurs on the call to sortIndex(...), not on the call to inSort(...), so I know that Basic is concerned about my use of the dot operator, disregarding my use of the Variant (or even the Any type) as well as my use of the isObject function as a condition.
The error also occurs any time the Null type or the Nothing object is passed to a procedure. This is less a pain to work around.
That accounts for about 96% of the errors I encounter during debugging, so if anyone could tell me how to coax Basic into letting me use the same parameter for both object and primitive types, it would be abundantly appreciated.