read oo Enum/Constant values with VBScript ...

Oliver Brinzing <[email protected]> Wed, 16 Mar 2011 09:16:58 +0100
Newsgroups gmane.comp.openoffice.devel.api
Message-ID <[email protected]>
Hi,

is it legal to use the following source code for reading oo Enum/Constant values ?
cause i found all vbscript examples seem to use direct values instead of constants, for example:
http://wiki.services.openoffice.org/wiki/Documentation/DevGuide/ProUNO/Bridge/Automation_Bridge

and i am not a vba expert ;-)

Regards

Oliver

'This is a VBScript example
Set objServiceManager= WScript.CreateObject("com.sun.star.ServiceManager")
Set objCoreReflection= objServiceManager.createInstance("com.sun.star.reflection.CoreReflection")

'get some constant values
MsgBox "PARAGRAPH_BREAK: " & GetConstantValue("com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK"),
64, "Constants"
MsgBox "SOFT_HYPHEN: " & GetConstantValue("com.sun.star.text.ControlCharacter.SOFT_HYPHEN"), 64,
"Constants"
MsgBox "HARD_SPACE: " & GetConstantValue("com.sun.star.text.ControlCharacter.HARD_SPACE"), 64,
"Constants"

MsgBox "ALWAYS_EXECUTE_NO_WARN: " &
GetConstantValue("com.sun.star.document.MacroExecMode.ALWAYS_EXECUTE_NO_WARN"), 64, "Constants"

'get some enum values
MsgBox "PREV: " & GetEnumValue("com.sun.star.text.PageNumberType", "PREV"), 64, "Enums"
MsgBox "CURRENT: " & GetEnumValue("com.sun.star.text.PageNumberType", "CURRENT"), 64, "Enums"
MsgBox "NEXT: " & GetEnumValue("com.sun.star.text.PageNumberType", "NEXT"), 64, "Enums"

Function GetEnumValue(cName, cValue)
'    GetEnumValue = objCoreReflection.forName(cName).getField(cValue).get(Nothing)
    If objCoreReflection.hasByHierarchicalName(cName) Then
       Set oIDL = objCoreReflection.getByHierarchicalName(cName)
       GetEnumValue = oIDL.getField(cValue).get(Nothing)
       Exit Function
    End If
    GetEnumValue = ""
End Function

Function GetConstantValue(cName)
   Set oContext =
objServiceManager.createInstance("com.sun.star.configuration.bootstrap.BootstrapContext")
   Set oTDM = oContext.getValueByName("/singletons/com.sun.star.reflection.theTypeDescriptionManager")
   If oTDM.hasByHierarchicalName(cName) Then
       GetConstantValue = oTDM.getByHierarchicalName(cName)
       Exit Function
   End If
   GetConstantValue = ""
End Function

-- 

GnuPG key 0xCFD04A45: 8822 057F 4956 46D3 352C 1A06 4E2C AB40 CFD0 4A45
signature.asc (application/pgp-signature, 260 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.10 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAk2AcgIACgkQTiyrQM/QSkW5qwCeP6ws08nTfafOqF+rFSF/fWSq
aS8An1KjjQXlbVnOj1lJqKcAjvwOD31Y
=U6Xu
-----END PGP SIGNATURE-----