【问题标题】:How to get the value of a Text box - LibreOffice Base如何获取文本框的值 - LibreOffice Base
【发布时间】:2018-03-20 14:55:13
【问题描述】:

我想做的很简单。

我在 LibreOffice Base 中有一个表单,其中包含一个用于输入一些数据的文本框和一个用于执行宏的按钮。 现在我想通过单击按钮上的宏获取文本框的输入值并使用 Print("...") 函数进行打印。

这是我到目前为止所得到的。不多,但也许是一个开始:

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

感谢任何形式的帮助!

【问题讨论】:

    标签: libreoffice base basic


    【解决方案1】:

    我自己找到了答案。关键是让子程序有一个参数,因为宏用于按钮上的执行。在事件中,您可以获得作为表单的 Parent,从那里您可以获得文本框及其当前值。对我来说效果很好。

    这里是代码

    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
    

    【讨论】:

      【解决方案2】:

      使用 Access2Base API 会很容易。

      【讨论】:

      • 正如目前所写,您的答案尚不清楚。请edit 添加其他详细信息,以帮助其他人了解这如何解决所提出的问题。你可以找到更多关于如何写好答案的信息in the help center
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-07-28
      • 1970-01-01
      • 2021-04-06
      • 2012-06-04
      • 1970-01-01
      • 2023-04-05
      • 1970-01-01
      相关资源
      最近更新 更多