Platform: LO Basic, v7.3.2.2 (Community), build 49f2b1bff42cfccbd8f788c8dc32c1c309559be0, running on OSX 10.15.7
Am curious about the need for the add-in function getDec2Hex’s first parameter, an “XPropertySet” object.
According to
a portion of the Libre help site, the function is part of the com.sun.star.sheet.addin.XAnalysis service.
In a spreadsheet you’d call “Dec2Hex(VALUE [, PLACES])”, but in a macro it’s “ADD-IN OBJECT.getDec2Hex(XProps Object, VALUE, PLACES)”
The add-in service is shown here
XPropertySet is an interface, shown here
To use any add-in function in a macro, one must first create a reference to the service:
Dim myAddInFuncs As Object
myAddInFuncs = createUnoService(“com.sun.star.sheet.addin.Analysis”)
The XPropertySet is also required:
Dim myXProps As Object
myXProps = com.sun.star.beans.XPropertySet
Declaring myXProps results in a variant with two “Out of Scope” sub-entries - Name, and Parent - though they’re not properties, as attempting to assign values to them (i.e, myXProps.Name = “MyName”) results in a “Property or method not found” error.
Let’s convert a decimal value to its hex equivalent, storing the result in a string variable, “sHex”.
LO source shows that getDec2Hex has three parameters:
An object, “myXProps” (shown above)
A Double, “Value” (the number being converted)
A Variant, “Places” (the number of digits to be returned)
Note that unlike calling Dec2Hex in a spreadsheet, with its one required parameter (the number to convert, and the optional number of places - up to 10 - to display), all three parameters to getDec2Hex are required, and even though the “Places” parameter is shown to be a variant, it needs to be quoted as if it’s a string or you’ll get an error.
Also, while the resulting hex value will be zero-padded to the number of places, the value of that parameter must must at least enough digits to accommodate the output - though not more than 10 - or you’ll also get an error:
Dim sHex As String
sHex = myAddInFuncs.getDec2Hex(myXProps, “9024416”, “6”)
Here, we’ve converted the decimal number 9024416, with the contents of sHex becoming “89B3A0”.
The limit on the “Places” parameter to 10 digits appears to be due to the “Value” parameter, it being a Double, or “Long” integer, which has a maximum of value 2147483647.
However, since that max value translates in hex to “7FFFFFFF”, it’s unclear why the maximum value for “Places” is not instead 8.
It’s also the case that, as the result gets zero-padded to the value of the “Places” parameter, chances are you’ll end up with leading zeros. (With places of “9” instead of “6”, the above result would instead be “00089B3A0”). By making the “Places” parameter required, you might as well always set it to “8” just to be safe, and unless you need them, remove any extra zeros from the start of the result.
Perhaps this particular function, or the add-in service in general, is being refactored, and this behavior, along with the way Dec2Hex is called, will change in the future.
Otherwise, it’s a bit of a mystery, perhaps a holdover from some super-old, crufty OpenOffice code.
As things stand now, since the two members of XPropertySet contain no apparent data, besides the obvious answer of “because it’s in the function declaration”, what purpose does it serve in the function call?