Is there a way for a Basic macro to detect what application is running it?

Here's my problem:

I have both Apache OpenOffice and LibreOffice installed and I use them
both. I have quite a few Calc files with Basic macros. Today I found my
first difference between the Basic API in LibreOffice vs. Apache OpenOffice:

Dim Dlg As Object, Ctl As Object
DialogLibraries.LoadLibrary("Standard")
Dlg=CreateUnoDialog(DialogLibraries.Standard.ElDialog)
Ctl=Dlg.getControl("DateField")

Now, I want to use Ctl.setDate(myDate) and myDate=Ctl.getDate(), and here's
the difference:
In Apache OpenOffice, myDate is a Long. Today's date, 2014-10-19, is
represented as 20141019. I made two functions to convert to and from the
format I needed.

When running my macro in LibreOffice, the macro was interrupted by an error
message, of course. After some debugging I found that the LibreOffice
version of Ctl.setDate/Ctl.getDate works with a struct:
Type DateType
Year As Long
Month As Long
Day As Long
End Type

This is of course not a big deal, I can make the macro accept both formats,
but the macro need to know if LibreOffice or Apache OpenOffice is running
it. How can I do that? I have tried to find the answer myself, both using
xray and searching the web, but so far nothing.

Kind regards

Johnny Rosenberg
ジョニー・ローゼンバーグ

Hi Johnny,

You might distinguish it with Basic function IsUnoStruct?

Kind regards
Regina

Johnny Rosenberg schrieb:

Quickly looking through the (not very user friendly) help for LibreOffice
Basic, the closest thing I found is GetSolarVersion, but that's probably
not enough.

While checking if the type is a struct can be a good workaround, it's not
completely future-proof; there is a need for a function to distinguish
between version of the Basic API (not only between AOO and LO).

A
​ctually there was another change from the post that I put before, the
Setup.xcu seems to be replaced by the ​registrymodifications.xcu

This has an ID check that list the following node:
  <item oor:path="/org.openoffice.Setup/Office">
    <prop oor:name="LastCompatibilityCheckID" oor:op="fuse">
      <value>411m6(Build:9775)</value>
    </prop>
  </item>

Unfortunately there is no such thing as a vendor name, but I hink this
could be good enough, unless someone come with a better node.

Johnny, Regina ,

under "tools" we have a function GetProductName()
who returns for me "LibreOffice4.2"

hope it helps

Fernand

Hi Fernand,

Fernand Vanrie schrieb:

Johnny, Regina ,

under "tools" we have a function GetProductName()
who returns for me "LibreOffice4.2"

hope it helps

Thanks for the hint to the application libraries. It works in Apache OpenOffice too.

Kind regards
Regina

Hi to all,

the most simple approach to distinguish the different behavior is to use an error handler.

In the latest version of my translation of Andrew Pitonyak's OOME I give an example (see pp. 605-609). Andrew has changed his example to just handle LO alone.

Have a look at https://www.uni-due.de/~abi070/ooo.html

Greetings
Volker

I got a PM from Johnny feeling sorry that his German couldn't be profound enough to follow a lengthy course of explanations.

So it's my turn to feel sorry for taking it for given that my post could suffice. I will be more precise.

I need to explain why I consider it more expensive to control the code by the product name than by an error handler. The format change of the date *and time* controls started with LO 4.1 as far as I know. Maybe you can rely on this. But who knows at which point of time the AOO developers will decide to follow their colleagues and likewise change their API? And what about some other OpenOffices? (I don't know anything about them.)

This is the listing in question with the comments in English:

Listing 534. Initialize a date control to today’s date (works with all versions of AOO and LO).
   REM Initialize the date control.
   REM Set the initial date to TODAY.
   Dim tToday As Date
   tToday = Date()

   On Error Goto LO
   REM Try to initialize the control with a Long Integer.
   REM This is the correct format for AOO and for older versions of LO.
   oOOMEDlg.getModel().getByName("MyDateField").Date = CdateToIso(tToday)
   On Error Goto 0 'Clear the error handler.
   Goto GoOn

   LO:
   REM On Error the control is initialized using a structure.
   REM This is the correct format for newer versions of LO.
   On Error Goto 0 'Clear the error handler to prevent an infinite loop,
                    'in case the macro runs into some other runtime error.
   Dim oToday As New com.sun.star.util.Date
   oToday.Year = Year(tToday)
   oToday.Month = Month(tToday)
   oToday.Day = Day(tToday)
   oOOMEDlg.getModel().getByName("MyDateField").Date = oToday

   GoOn:

Greetings
Volker