How to assign variables to objects that can be passed to macros in Impress?

I will create a visual novel with LibreOffice which uses macros triggered by mouse clicks on buttons. The following is a simplified example. There are a total of 4 slides. Each slide has 3 buttons, which when clicked on move the presentation to slide n. I wrote 4 macros, one for moving to each slide. To Slide n activates MoveTon.

Sub MoveTo1

Dim oDoc As Object
Dim oPresentation As Object
Dim oController As Object

oDoc = ThisComponent

oPresentation = oDoc.getPresentation()

oController = oPresentation.getController()

oController.gotoSlideIndex(0)

End Sub

Sub MoveTo2

Dim oDoc As Object
Dim oPresentation As Object
Dim oController As Object

oDoc = ThisComponent

oPresentation = oDoc.getPresentation()

oController = oPresentation.getController()

oController.gotoSlideIndex(1)

End Sub

Sub MoveTo3

Dim oDoc As Object
Dim oPresentation As Object
Dim oController As Object

oDoc = ThisComponent

oPresentation = oDoc.getPresentation()

oController = oPresentation.getController()

oController.gotoSlideIndex(2)

End Sub

Sub MoveTo4

Dim oDoc As Object
Dim oPresentation As Object
Dim oController As Object

oDoc = ThisComponent

oPresentation = oDoc.getPresentation()

oController = oPresentation.getController()

oController.gotoSlideIndex(3)

End Sub

However in production there will be at least 50 and perhaps over 200 slides so writing the same function that many times will make maintaining the code much harder. I considered writing a single function which reads the integer in the buttons to determine where to move to but in the final project the text will be stuff like Go on a date, Buy her a present instead of To Slide n so that wouldn’t work either.

What could work is hardcoding an invisible variable to each button so that when pressed on, the variable is passed to the function and it moves to the corresponding slide.

Sub MoveTo

Dim oDoc As Object
Dim oPresentation As Object
Dim oController As Object
Dim oSlideIndex As Integer

oDoc = ThisComponent

oPresentation = oDoc.getPresentation()

oController = oPresentation.getController()

oController.gotoSlideIndex(oSlideIndex)

In the code above oSlideIndex is an integer that is passed to MoveTo. Is this possible? If so, can it be extended so that a button can contain multiple variables of different types? (In production many more features will be added so I need macros)

Edit: The buttons are simple circles/ellipses and not anything more fancier.

I never use impress, but basically I assume a “button” in an impress slide is just an ordinary FormControl. Depending on the type a FormControl will raise an event on specific (mouse-) actions, and call the assigned macro if any. The macro gets passed a parameter giving information about the sending control.
pEvent.Source.Model should give access to the properties of the control, among them the string property .Tag , unfortunately named “Additional information” in the control’s editor.
This string property I use to pass any number of strings assigned to variables in the way standardised for query strings in web URLs. If you are interested you can get the code I use for the purpose (not today).

@Lupp Thank you for your reply! I would be happy to learn from your code. Actually the “buttons” I made are just plain circles with interactions set up so that on click they will run the macros. I will have to study FormControl then.

Yes. I had missed this, and due to the mentioned fact that I never use Impress myself, and the other fact that Impress and Draw are very similar in design mode I didn’t even realise that some(?) shapes in impress behave very different as compared to similar shapes in Draw and come with the Interaction feature for use during runtime of the presentation.

Having looked into Impress at least a little, I regret my uninformed comments, and would like to remove my answer which actually is none. However it also contains a bit of useful(?) code, and I therefore leave that answer untouched.

Concerning the original question:
A Sub called as the interaction defined for your button-shapes don’t get any arguments passed. They only know THAT they were called, but not by what action or from what shape. To get something like a parmetrised response, you need to define an extra interaction Sub for every as-if-button, and this Sub then can contain the additional information as a hard-coded value, and use it when calling the generalising Sub acting for many shape-interactions.

Hope this was somehow clear.

Use the Tag property, it is a text string that you can use as you wish.

Look this example.
foro.odp (26.7 KB)

@elmau Would you please elaborate further? I should have made it clear that the buttons are plain circles and when I go to Edit Style I don’t see ```Tag````s.

Probably we have to make clear that this isn’t the place to get a taylor-made tutorial for everything somebody asks for. @elmau and myself studied and trained a lot reading papers about programming and the LibreOffice API and the …

You may need to also study first.

Surely you will make use of the famous texts by Andrew Pitonyak available from www.pitonyak.org/oo.php. Start with examples from the “English Macro Document” and read relevant parts of “The Book” then depending on your specific tasks.

Precise API information you mostly find here.

Fortunately I found the time to prepare an example for you. It contains a ContrtolButton and a linked text portion inserted into an image.

See my “Answer”.

Just an example for serious studies. It exemplifies what I already told in comments.

disask95328demoPassingVariablesViaFormControlTagOrVndLink.odg (59.9 KB)