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.