Can anyone help on using BASIC to report on all the properties and methods of a database object?
I’ve tried two ways, one suggested by ChatGPT and the other from the LibreOffice help web site - the section “SFDocuments.Document service”.
You can see below for the results
1 ThisDatabaseDocument isn’t recognised
2, DocumnentProperties isn’t recognised.
I’m hoping that this is just a user error in that I haven’t got some vital library or service loaded but can anyone advise?
Thanks
Nick
1, REM code from chatGPT
Sub DisplayPropertiesOfThisDatabaseDocument()
Dim i As Integer
Dim properties() As String
’ Get the properties of ThisDatabaseDocument
properties = ThisDatabaseDocument.Properties.getPropertyNames() 'Line throwing the error message
' Display each property
For i = LBound(properties) To UBound(properties)
MsgBox "Property name: " & properties(i) & vbCrLf & _
"Value: " & ThisDatabaseDocument.Properties.getPropertyValue(properties(i))
Next i
End Sub
When I try to use this code I get the error message at the line “properties = ThisDatabaseDocument.Properties.getPropertyNames()”
The error number raised is 12
The error description is "Variable not defined.
Additional information: ThisDatabaseDocument"
2, I also tried using the code noted at SFDocuments.Document service
Sub LO_BASIC_example_to_show_all_doc_properties()
REM The code noted at SFDocuments.Document service
GlobalScope.BasicLibraries.loadLibrary(“ScriptForge”)
Dim ui as Variant : Set ui = CreateScriptService(“UI”)
Dim oDoc as Object
Set oDoc = ui.OpenDocument(ThisComponent.URL)
Dim propDict as Object
Set propDict = oDoc.DocumentProperties ’ Line throwing the error message
Dim keys as Variant : propKeys = propDict.Keys
Dim k as String, strProp as String
For Each k In propKeys
strProp = strProp & k & ": " & propDict.Item(k) & CHR$(10)
Next k
MsgBox strProp
end sub
This fails at the line “Set propDict = oDoc.DocumentProperties” with the message and the property or method “DocumentProperties” isn’t recognised.
3, LibreOffice environment
Version: 7.6.6.3 (X86_64) / LibreOffice Community
Build ID: d97b2716a9a4a2ce1391dee1765565ea469b0ae7
CPU threads: 8; OS: Linux 6.5; UI render: default; VCL: gtk3
Locale: en-GB (en_GB.UTF-8); UI: en-US
Calc: threaded
I’m using Xubunutu 22.04.