如何获取文本框的值 - LibreOffice Base
How to get the value of a Text box - LibreOffice Base
我想做的很简单。
我在 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
感谢任何形式的帮助!
我自己找到了答案。关键是让子例程有一个参数,因为宏是在按钮上执行时使用的。在事件中,您可以获得表单的父级,从那里您可以获得文本框及其当前值。对我来说很好用。
这是代码
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
使用 Access2Base API 会很容易。
我想做的很简单。
我在 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
感谢任何形式的帮助!
我自己找到了答案。关键是让子例程有一个参数,因为宏是在按钮上执行时使用的。在事件中,您可以获得表单的父级,从那里您可以获得文本框及其当前值。对我来说很好用。
这是代码
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
使用 Access2Base API 会很容易。