Search code examples
libreofficeradixbasic

How to get the value of a Text box - LibreOffice Base


What i want to do is fairly simple.

I have a form in LibreOffice Base with a text box to enter some data and a button to execute a macro. Now i want to get with the macro on the clicking button the entered value of the text box and print it with the Print("...") function.

This what i got so far. Not much, but maybe a start:

Sub TestMacro
   dim oForm as object
   dim oTextbox as object
   dim content as object

   oForm = thisComponent.drawpage.forms.getByName("form_a")
   oTextbox = oForm.getByName("testbox")
   content = oTextbox.getText()

   Print(content)
End Sub

Any kind of help is appreciated!


Solution

  • I found the answer on my own. The key was to let the subroutine have a parameter as the macro is used on the execution on the button. Over the event you can get the Parent which is the form, from that on you can get the text box and the Current Value of it. Works just fine for me.

    Here is the code

    Sub TestMacro(oEvent as object)
    
       DIM oForm AS OBJECT
       DIM oField as object
       DIM oTField as object
    
       'gets the button
       oTField = oEvent.Source.Model
       'gets the parent of the button which is the form
       oForm = oTField.Parent
       'gets the text field based on its name
       oField = oForm.getByName("testbox")
       'prints the value of the textfield
       Print(oField.getCurrentValue)
    
    End Sub