How to Execute Code when a Button is Clicked

Hello everyone. I’m trying to use the basic programming language to code a custom dialog box but can’t seem to figure out how to execute code when a button is clicked. Can someone help me with this or point me in the direction of where to find the answer?

Basically, I have a custom dialog box I made that includes a list box populated with some items. After the user selects an item from the list and clicks on the “Select” button, I want to execute some code. Problem is, I can’t figure out how to do this.

I was thinking it’d be something like the following:

oDialogModel = oDialog1.Model
oSelectModel = oSelectModel.getByName(“SelectButton”)
…execute some code
End Event

I know that code won’t work but do you get the idea? Where do I go and/or what do I need to do to get the libreoffice basic code to sense when a button within my custom dialog box is clicked and execute the appropriate code?

Thanks in advance for you time and reply.


1 Like

While @JohnSUN answered the question how a macro can know wich button called the macro, I’m suspecting you struggle at the point of attaching a macro to a button.
Therefore you have to create the button and edit the properties of the button. You find a tab with possible events, where you can then select an action to perform. Instead of direct actions you can always set a macro there.
Please check the following thread:

1 Like

Thank you for the help. These replies were what I needed.

I saw the events tab originally but didn’t make the connection that “Execute action” was the same thing as “On click” :confused:

1 Like