[Solved] Runtime error 35 CDateToUnoDate

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
artem78
Posts: 12
Joined: Wed Jun 07, 2023 8:21 pm

[Solved] Runtime error 35 CDateToUnoDate

Post by artem78 »

I have dialog with date field which value I need to set to today. This code works in LibreOffice, but not in OpenOffice:

Code: Select all

DialogLibraries.LoadLibrary("Standard")
Dim Dlg As Object
Dlg = CreateUnoDialog(DialogLibraries.Standard.InputDataDialog)
Dlg.getControl("DateField").Date = CDateToUnoDate(Date())
In OpenOfice it raises runtime error 35 CDateToUnoDate.

How to make this code works in both LibreOffice and OpenOffice?

Thanks.
Last edited by artem78 on Thu Jun 08, 2023 9:52 am, edited 1 time in total.
OpenOffice 4.1.14 on Windows 7 and LibreOffice 6.4.7.2 on Linux Mint 20.3
User avatar
RoryOF
Moderator
Posts: 34618
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Runtime error 35 CDateToUnoDate

Post by RoryOF »

Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
JeJe
Volunteer
Posts: 2785
Joined: Wed Mar 09, 2016 2:40 pm

Re: Runtime error 35 CDateToUnoDate

Post by JeJe »

OO doesn't have that function, CDateToUnoDate, natively so you have to write it - its trivial to do.

Note in OO the year in the Date struct is an unsigned short, in LO a short.

Code: Select all

function CDateToUnoDateOOAndLO(d as Date) as com.sun.star.util.Date
dim dd as new com.sun.star.util.Date
with dd
.month= month(d)
.day = day(d)
.year = year(d)
CDateToUnoDateOOAndLO = dd
end with
end function
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
JeJe
Volunteer
Posts: 2785
Joined: Wed Mar 09, 2016 2:40 pm

Re: Runtime error 35 CDateToUnoDate

Post by JeJe »

The date field value looks to be a long though (as per RoryOF's link) - so scrap that - instead you'll need to test for whether its LO or OO and use CDateToIso if its OO.

There's a lot of divergence between OO and LO in dialog controls now.

Edit: you may find this thread of interest
viewtopic.php?t=82181
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
User avatar
Zizi64
Volunteer
Posts: 11363
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Runtime error 35 CDateToUnoDate

Post by Zizi64 »

How to make this code works in both LibreOffice and OpenOffice?
I suggest you to install the LibreOffice (same version on all of the related computers).
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
artem78
Posts: 12
Joined: Wed Jun 07, 2023 8:21 pm

Re: Runtime error 35 CDateToUnoDate

Post by artem78 »

JeJe wrote: Thu Jun 08, 2023 12:53 am you'll need to test for whether its LO or OO and use CDateToIso if its OO.
I made this trick to detect LO/OO and it works:

Code: Select all

if TypeOf Dlg.getControl("DateField").Date is com.sun.star.util.Date Then
	' Code for LibreOffice
	Dlg.getControl("DateField").Date = CDateToUnoDate(Date())
Else
	' Code for OpenOffice
	Dlg.getControl("DateField").Date = CDateToIso(Date())
End If
Thanks.
OpenOffice 4.1.14 on Windows 7 and LibreOffice 6.4.7.2 on Linux Mint 20.3
User avatar
Lupp
Volunteer
Posts: 3553
Joined: Sat May 31, 2014 7:05 pm
Location: München, Germany

Re: [Solved] Runtime error 35 CDateToUnoDate

Post by Lupp »

On Windows 10: LibreOffice 24.2 (new numbering) and older versions, PortableOpenOffice 4.1.7 and older, StarOffice 5.2
---
Lupp from München
Post Reply