[Solved] Object variable not occupied

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
Johnny John
Posts: 12
Joined: Sat Jan 07, 2017 5:24 pm

[Solved] Object variable not occupied

Post by Johnny John »

I have a problem:

In a document did I put these button:
Image

The name of the button is "JaNein":
Image

So did I assign the button:
Image

If I activate the button, it appears these error alert:
Image

What error did I do?

Thank you very much for your help

Gianni
Last edited by Johnny John on Sun Jan 08, 2017 6:46 pm, edited 2 times in total.
OpenOffice 3.1 on Windows 7
User avatar
Zizi64
Volunteer
Posts: 11494
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Object variable not occupied

Post by Zizi64 »

The 'JaNein' is an object on the graphical leyer. You must get it first:

Code: Select all

JaNein = Thiscomponent. ... etc ... .

Then you can use the properties of the 'JaNein' object. You need study the API descriptions, and must use the API functions. Start with Andrew pitonyak's books.
Last edited by Zizi64 on Sat Jan 07, 2017 6:40 pm, edited 2 times in total.
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.
FJCC
Moderator
Posts: 9563
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Object variable not occupied

Post by FJCC »

To expand a bit on Tibor's answer. The code to print the label of the button could be

Code: Select all

oDP = ThisComponent.DrawPage
oForms = oDP.Forms
oF = oForms.getByIndex(0)
oJaNein = oF.getByName("JaNein")
print oJaNein.Label
The button is part of a Form which is on the DrawPage of the document.
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
User avatar
Zizi64
Volunteer
Posts: 11494
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Object variable not occupied

Post by Zizi64 »

or you can get it trough the Event in the associated subroutine:
viewtopic.php?f=45&t=62024
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.
Johnny John
Posts: 12
Joined: Sat Jan 07, 2017 5:24 pm

Re: Object variable not occupied

Post by Johnny John »

Thank you very much for the quick answers, Zizi64 and FJCC.
OpenOffice 3.1 on Windows 7
Johnny John
Posts: 12
Joined: Sat Jan 07, 2017 5:24 pm

Re: Object variable not occupied

Post by Johnny John »

I tried your proposal, FJCC, but this is what I got:

Image
OpenOffice 3.1 on Windows 7
FJCC
Moderator
Posts: 9563
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Object variable not occupied

Post by FJCC »

Please upload a document as an example It will be a lot easier to find the problem if we can look at the actual document.
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
Johnny John
Posts: 12
Joined: Sat Jan 07, 2017 5:24 pm

Re: Object variable not occupied

Post by Johnny John »

Here is the document, FJCC.
Attachments
Probe mit Schaltfläche LO.odt
(9.86 KiB) Downloaded 220 times
OpenOffice 3.1 on Windows 7
FJCC
Moderator
Posts: 9563
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Object variable not occupied

Post by FJCC »

Here is a working version.
Attachments
Button_macro_FJCC.odt
(11.29 KiB) Downloaded 190 times
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
Johnny John
Posts: 12
Joined: Sat Jan 07, 2017 5:24 pm

Re: Object variable not occupied

Post by Johnny John »

Thank you very very much, FJCC. Your Macro works very well with LibreOffice. But not with Apache OpenOffice Portable, which I installed in the meantime with PortableApps. Is it possible to explain this error? As you see, OpenOffice works not with your good new macro but with my bad old macro, which the program loads instead!!. For me it is very strange. I tried it many times, always with the same result. Is it possible that this error is connected with the portable version?

If I try to activate the macro with the text editor of OO nothing happens. The error is shown if I run the macro in the macro editor of OO.

Image

Image

Image

Image

Image

Image
Last edited by Johnny John on Mon Jan 09, 2017 1:29 pm, edited 1 time in total.
OpenOffice 3.1 on Windows 7
User avatar
Zizi64
Volunteer
Posts: 11494
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Object variable not occupied

Post by Zizi64 »

The FJCC's example file works fine in my AOO portable 4.1.3 and LO 4.4.7, and LO portable 5.2.3

The name of the Button object is 'Button1' in the FJCC's example file.
As I see it, you have tried actualize the example macro code for your file. Don't forget to change the object name in the code snippet (or the name of your button...)

...or please upload again your actualized example file here...

note:
the embedded macro code located in the example file will work in that specific document only. You must place the code into a Module of the MyMacros/Standard directory of the office suite - if you want use it with other documents....
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.
Johnny John
Posts: 12
Joined: Sat Jan 07, 2017 5:24 pm

Re: Object variable not occupied

Post by Johnny John »

Zizi64 wrote:The FJCC's example file works fine in my AOO portable 4.1.3 and LO 4.4.7, and LO portable 5.2.3

The name of the Button object is 'Button1' in the FJCC's example file.
As I see it, you have tried actualize the example macro code for your file. Don't forget to change the object name in the code snippet (or the name of your button...)

...or please upload again your actualized example file here...

note:
the embedded macro code located in the example file will work in that specific document only. You must place the code into a Module of the MyMacros/Standard directory of the office suite - if you want use it with other documents....
I cannot remember to have yesterday changed anything in the FJCC's example file. What I remember is that I was extremely surprised for the appearing of the code of a file which I had written before the changes of FJCC. I tried again and again and again and again. Always appeared my old code when I had loaded only the file of FJCC in the program APACHE OpenOffice Portable 4.1.3 which I installed with PortableApps in my USB-Stick.
And today it is the same. I work today with another computer. Is there another explanation than that OpenOffice Portable 4.1.3 Portable has a bug? Other perhaps, that PortableApps has a bug?
With LibreOffice Portable Version: 5.2.3.3 FJCC's example file works perfectly.
To be sure that I did not commit an error, I did loaded down FJCC's example file 3 times yesterday and the fourth time today. I paid extreme attention but always with the same results.

Image

Image

Image

Image

I tried it again with OpenOffice (PortableApps):

Image

Again the same thing: Nothing happens, if I push the button. But if I let the old bad code run, than it appears unsurprisingly the same bad error. OpenOffice (PortableApps) loads the text of the file of FJCC together with the code of my old file!
OpenOffice 3.1 on Windows 7
User avatar
Zizi64
Volunteer
Posts: 11494
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Object variable not occupied

Post by Zizi64 »

OpenOffice (PortableApps) loads the text of the file of FJCC together with the code of my old file!
It is unbeliveable...

I tried it again with FJCC's file in my AOO PORTABLE 4.1.3. version, and it works fine. (There is not installed the Portable Apps frame application, but only installed the AOO portable.)
The macro is stored in the file, and that code is associated to the "Execute action" event of the button named 'Button1'. The name of the macro is 'Main'.

(I usually use the event named "Mouse button pressed".)
Please click on the picture...
Please click on the picture...
Last edited by Zizi64 on Sun Jan 08, 2017 3:54 pm, edited 1 time in total.
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.
Johnny John
Posts: 12
Joined: Sat Jan 07, 2017 5:24 pm

Re: Object variable not occupied

Post by Johnny John »

Zizi64 wrote:
OpenOffice (PortableApps) loads the text of the file of FJCC together with the code of my old file!
It is unbeliveable...

I tried it again with FJCC's file in my AOO PORTABLE 4.1.3. version, and it works fine. (There is not installed the Tortable Apps frame application, but only installed the AOO portable.)
The macro is stored in the file, and that code is associated to the "Execute action" event of the button named 'Button1'. The name of the macro is 'Main'.

(I usually use the event named "Mouse button pressed".)
Macro in the document.png
It is unbelieveable...

I tried it again with OpenOffice Portable, with LIbreOffice Portable and with LibreOffice Installed. Same results.

Conclusion:

It is unbelieveable... but I see no other possibility than to believe it.
OpenOffice 3.1 on Windows 7
Johnny John
Posts: 12
Joined: Sat Jan 07, 2017 5:24 pm

Re:[Solved] Object variable not occupied

Post by Johnny John »

Perhaps I begin to understand the unbelievable:

I opened FJCC’s file again with my OpenOffice. Then I opened the register events. It seems so, as if the sub Main in the document is associated to the "Execute action" event of the button named 'Button1'.

But as I tried to associate again, I received a warning, meaning that this action is at the present not possible because of the missing of JRE!

Because I work in a public library where I have no permission to install a program on the PC and because I don’t know whether it is possible to install JRE in a portable program or not, I must resign concerning the document of FJCC.

But the sub of FJCC works fine with LibreOffice and this is important.

Thank you, FJCC, and thank you, Zizi64.

Image

Image

Image
OpenOffice 3.1 on Windows 7
Johnny John
Posts: 12
Joined: Sat Jan 07, 2017 5:24 pm

Re: [Solved] Object variable not occupied

Post by Johnny John »

I think that I can now definitely say that my OpenOffice has a bug.
Image
I did create with it a new document and created the button and wrote and associated the macro.
To associate the macro it was necessary to push 15 (fifteen) times the button “Macro”! But it worked and this without installing JRE!
Then I saved the file, closed OpenOffice and started it again opening the saved file. It did not work!
I became the warning that macros were not permitted because of security reasons! I did open the options-register and did put the level to the minimum and added the directory of the saved file to the reliable sources. Nevertheless I was not permitted to run the macro! As I created it I was permitted. Later no more!
After having opened the same file with LibreOffice it worked perfectly!

A last question, Zizi64 please: from what source did you get OpenOffice 4.1.3 portable? Could it be, that the program from PortableApps has more bugs than others?
OpenOffice 3.1 on Windows 7
User avatar
Zizi64
Volunteer
Posts: 11494
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: [Solved] Object variable not occupied

Post by Zizi64 »

A last question, Zizi64 please: from what source did you get OpenOffice 4.1.3 portable? Could it be, that the program from PortableApps has more bugs than others?
http://portableapps.com/apps/office/openoffice_portable
http://portableapps.com/apps/office/lib ... e_portable

I think that I can now definitely say that my OpenOffice has a bug.
I think, it is not a bug. (I have 32 bit JRE on my Win7 PC.)
The AOO has a higher dependency of the JRE than the LibreOffice. The developer team of the LibreOffice forces to reduce the JRE-dependency of the LibreOffice.
(The AOO is developed very slowly now.)
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.
User avatar
Villeroy
Volunteer
Posts: 31348
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: [Solved] Object variable not occupied

Post by Villeroy »

Zizi64 wrote:
I think that I can now definitely say that my OpenOffice has a bug.
I think, it is not a bug. (I have 32 bit JRE on my Win7 PC.)
The AOO has a higher dependency of the JRE than the LibreOffice. The developer team of the LibreOffice forces to reduce the JRE-dependency of the LibreOffice.
(The AOO is developed very slowly now.)
It is a severe case of wrong design. LO has still the same dependencies as OpenOffice with the exception of some obscure "helpers" under File>Wizards... It is very easy to check out. Just turn off Java in the options and walk through the list of JRE dependent features we collected in viewtopic.php?f=74&t=69896

In this particular context (when calling the dialogs which let you browse macros) you can ignore the JRE warnings. They are pointless as far as Basic and Python macros are concerned. If you patiently click away these warnings everything works as expected.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Johnny John
Posts: 12
Joined: Sat Jan 07, 2017 5:24 pm

Re: [Solved] Object variable not occupied

Post by Johnny John »

Villeroy wrote: If you patiently click away these warnings everything works as expected.
You must have a lot of patience to click away these warnings 15 (fifteen) times on every change.

Will the people to whom you give the macros be able to use them?
Or will perhaps their OpenOffice behave in another way then yours?
What if the receivers have no experience with programming?

I cannot understand why the OpenOffice and the LibreOffice teams cannot agree about synchronizing their products.
OpenOffice 3.1 on Windows 7
User avatar
Villeroy
Volunteer
Posts: 31348
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: [Solved] Object variable not occupied

Post by Villeroy »

Once you assigned your macros to the right events, everything works normally.
Johnny John wrote:I cannot understand why the OpenOffice and the LibreOffice teams cannot agree about synchronizing their products.
Apart from the OpenOffice name and logo there is nothing to synchronize with OpenOffice.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
User avatar
RoryOF
Moderator
Posts: 35096
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: [Solved] Object variable not occupied

Post by RoryOF »

There is a licensing problem. LibreOffice can use OO code, but OO cannot use LibreOffice code, for some reason of Apache policy.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.5 LTS
User avatar
Zizi64
Volunteer
Posts: 11494
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: [Solved] Object variable not occupied

Post by Zizi64 »

I cannot understand why the OpenOffice and the LibreOffice teams cannot agree about synchronizing their products.

The 'Apache OpenOffice' and the 'LibreOffice' are not commercial PRODUCTS.


There is not Apache OpenOffice TEAM now, but there are only a few developer.

"LibreOffice is the most actively developed free and open source office suite, a project of The Document Foundation. It was forked from OpenOffice.org in 2010..."
See the History part of this page:
https://en.wikipedia.org/wiki/LibreOffice
Certified developers of the Libreoffice:
https://www.documentfoundation.org/gethelp/developers/
Here a list of the developer persons of the Libreoffice, and other volunteers of the community project:
http://planet.documentfoundation.org/





...And please install the JRE if you want to work with the AOO or LO effectively...
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.
Post Reply