Beginner needs help with MRI, I think...

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
Kenneth.n.r
Posts: 3
Joined: Fri May 17, 2019 10:53 am

Beginner needs help with MRI, I think...

Post by Kenneth.n.r »

I have been tryinge for a few days, to create a checkbox, that will call a macro when changed.

I can make the checkbox, no problem there.
To ad the macro function, I've found some code that can make a button run a macro when pressed.
Trying to alter this code, to fit my needs is where I ran into trouble, I tried to use MRI to help me, but either MRI can't do what I need, or I don't know how to get MRI to do it.

The value for EventMethod are my problem, "MouseButtonPressed" isn't a valid value, I had hoped MRI could give me a list of valid options, but if it can, I don't know how.

Anyone who have an idea to how to get the valid options ?

Code: Select all

  
aEvent = CreateUnoStruct("com.sun.star.script.ScriptEventDescriptor")
  With aEvent
    .AddListenerParam = ""
    .EventMethod = "MouseButtonPressed"
    
    oMri.inspect(aEvent)
    
    .ListenerType = "XActionListener"
    .ScriptCode = sScriptURL
    .ScriptType = "Script"
  End With
LibreOffice 6.2, Windows 10
UnklDonald418
Volunteer
Posts: 1544
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: Beginner needs help with MRI, I think...

Post by UnklDonald418 »

Setting up a working listener can be tricky, fortunately in most cases you don't need to do that.
You didn't mention what type of document you are adding the Check Box to, ... but open the document in the Design Mode,
right click on the Check Box (you should see 6 green handles surrounding it) and select Control to open the Properties: Check Box dialog.
On the Events tab you will find a list of possible events that will trigger a macro, including Item Status Changed and Mouse Button Pressed.
Select the ellipsis to the right of the chosen event to open the Assign Action dialog.
Select Macro and navigate to the macro code you want to run.
Select OK to save you choice.
Exit the Design Mode and you should be able to trigger your macro with the chosen event.
If your problem has been solved, please edit this topic's initial post and add "[Solved]" to the beginning of the subject line
Apache OpenOffice 4.1.14 & LibreOffice 7.6.2.1 (x86_64) - Windows 10 Professional- Windows 11
Kenneth.n.r
Posts: 3
Joined: Fri May 17, 2019 10:53 am

Re: Beginner needs help with MRI, I think...

Post by Kenneth.n.r »

Sorry for the incomplete question.

I'm working in calc.
And I knew how to do it manually,
I need to create the checkbox by macro.
I have a member list that I take from an database, and I need a checkbox after each member.
The number of members isn't a constant, so I don't know the number of of checkbox's needed.
LibreOffice 6.2, Windows 10
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Beginner needs help with MRI, I think...

Post by Villeroy »

Forget about macro generated check boxes. Far too complicated for whatever purpose even if you are very familiar with this API. Use a true database with true input forms. Works for me since many years with zero or very few lines of macro code.

I think this is an XY problem: http://xyproblem.info/
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
JeJe
Volunteer
Posts: 2764
Joined: Wed Mar 09, 2016 2:40 pm

Re: Beginner needs help with MRI, I think...

Post by JeJe »

A more light weight alternative to a check box is to set a cell's string to either of the characters ☐ or ☑

That's all a check box is - one of those two characters drawn and optionally some text after it - depending on whether the condition is set or not.
Windows 10, Openoffice 4.1.11, LibreOffice 7.4.0.3 (x64)
Kenneth.n.r
Posts: 3
Joined: Fri May 17, 2019 10:53 am

Re: Beginner needs help with MRI, I think...

Post by Kenneth.n.r »

Villeroy might be right.

What I want to do is pull members from a database, and with a single mouse click mark the members who are present.

I want to use this to make random groups in a dart club, on practice days.

Xy problem eliminated.
LibreOffice 6.2, Windows 10
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Beginner needs help with MRI, I think...

Post by Villeroy »

Add a boolean field to the database, set it False, set it not nullable (true or false only but not null). Instantly the GUI shows a column of check boxes for every list item.

For a database that is connected to LibreOffice Base and without fiddling too long with the user interface, the modifications may look like this:

Code: Select all

ALTER TABLE "Invitations" ADD COLUMN "Acceptance" BOOLEAN;
UPDATE "Invitations" SET "Acceptance" = False;
ALTER TABLE "Invitations" ALTER COLUMN "Acceptance" BOOLEAN NOT NULL;
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
UnklDonald418
Volunteer
Posts: 1544
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

Re: Beginner needs help with MRI, I think...

Post by UnklDonald418 »

Taking the suggestion from Villeroy one step further, a simple query something like

Code: Select all

SELECT "FIRSTNAME", "LASTNAME" FROM "Invitations" WHERE "Acceptance" = TRUE ORDER BY RAND( )
will generate a random list of attendees.
If your problem has been solved, please edit this topic's initial post and add "[Solved]" to the beginning of the subject line
Apache OpenOffice 4.1.14 & LibreOffice 7.6.2.1 (x86_64) - Windows 10 Professional- Windows 11
Post Reply