Page 1 of 1

Beginner needs help with MRI, I think...

PostPosted: Fri May 17, 2019 11:04 am
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   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

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

PostPosted: Fri May 17, 2019 10:24 pm
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.

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

PostPosted: Sat May 18, 2019 7:40 am
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.

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

PostPosted: Sat May 18, 2019 9:50 am
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/

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

PostPosted: Sat May 18, 2019 12:06 pm
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.

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

PostPosted: Sat May 18, 2019 6:22 pm
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.

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

PostPosted: Sat May 18, 2019 7:52 pm
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   Expand viewCollapse view
ALTER TABLE "Invitations" ADD COLUMN "Acceptance" BOOLEAN;
UPDATE "Invitations" SET "Acceptance" = False;
ALTER TABLE "Invitations" ALTER COLUMN "Acceptance" BOOLEAN NOT NULL;

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

PostPosted: Sun May 19, 2019 12:02 am
by UnklDonald418
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.