Beginner needs help with MRI, I think...

Creating a macro - Writing a Script - Using the API

Beginner needs help with MRI, I think...

Postby Kenneth.n.r » Fri May 17, 2019 11:04 am

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   Expand viewCollapse view
 
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
Kenneth.n.r
 
Posts: 3
Joined: Fri May 17, 2019 10:53 am

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

Postby UnklDonald418 » Fri May 17, 2019 10:24 pm

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.6 & LibreOffice 6.1.5.2 - Windows 10 Professional
UnklDonald418
Volunteer
 
Posts: 1237
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA

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

Postby Kenneth.n.r » Sat May 18, 2019 7:40 am

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
Kenneth.n.r
 
Posts: 3
Joined: Fri May 17, 2019 10:53 am

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

Postby Villeroy » Sat May 18, 2019 9:50 am

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, no OpenOffice, LibreOffice 6.x
User avatar
Villeroy
Volunteer
 
Posts: 27295
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

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

Postby JeJe » Sat May 18, 2019 12:06 pm

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.
Openoffice 4.1.2
Windows 8
JeJe
Volunteer
 
Posts: 607
Joined: Wed Mar 09, 2016 2:40 pm

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

Postby Kenneth.n.r » Sat May 18, 2019 6:22 pm

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
Kenneth.n.r
 
Posts: 3
Joined: Fri May 17, 2019 10:53 am

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

Postby Villeroy » Sat May 18, 2019 7:52 pm

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   Expand viewCollapse view
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, no OpenOffice, LibreOffice 6.x
User avatar
Villeroy
Volunteer
 
Posts: 27295
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

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

Postby UnklDonald418 » Sun May 19, 2019 12:02 am

Taking the suggestion from Villeroy one step further, a simple query something like
Code: Select all   Expand viewCollapse view
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.6 & LibreOffice 6.1.5.2 - Windows 10 Professional
UnklDonald418
Volunteer
 
Posts: 1237
Joined: Wed Jun 24, 2015 12:56 am
Location: Colorado, USA


Return to Macros and UNO API

Who is online

Users browsing this forum: KeithOO and 6 guests