Comment être sur d’utiliser la bonne syntaxe sous VB .NET lorsqu’on interprète   oOBasic pour les commandes UNO ?

 

Par exemple réglage de la police d’une cellule sous Calc l’enregistreur de Macros nous donne :

 

sub CellulePolice

rem ----------------------------------------------------------------------

rem define variables

dim document   as object

dim dispatcher as object

rem ----------------------------------------------------------------------

rem get access to the document

document   = ThisComponent.CurrentController.Frame

dispatcher = createUnoService("com.sun.star.frame.DispatchHelper")

 

rem ----------------------------------------------------------------------

dim args1(4) as new com.sun.star.beans.PropertyValue

args1(0).Name = "CharFontName.StyleName"

args1(0).Value = ""

args1(1).Name = "CharFontName.Pitch"

args1(1).Value = 2

args1(2).Name = "CharFontName.CharSet"

args1(2).Value = -1

args1(3).Name = "CharFontName.Family"

args1(3).Value = 5

args1(4).Name = "CharFontName.FamilyName"

args1(4).Value = "Arial Rounded MT Bold"

 

dispatcher.executeDispatch(document, ".uno:CharFontName", "", 0, args1())

 

 

end sub

 

 

Lorsque je transpose sous VB .NET de la sorte .. ça ne fonctionne pas !

 

Dim oServiceManager As Object, oDispatcher As Object

    Dim oDesktop As Object, oDocument As Object, oSel As Object, oFeuille As Object

    Dim oJeCherche As Object, oMonCurseur As Object, oMonTexte As Object

 

Public Function ChargerService() As Boolean

        'On Error GoTo sortie

        oServiceManager = CreateObject("com.sun.star.ServiceManager")

        oDesktop = oServiceManager.createInstance("com.sun.star.frame.Desktop")

        oDispatcher = oServiceManager.createInstance("com.sun.star.frame.DispatchHelper")

 

        ChargerService = True

        'Sortie:

        'LoadService = False

 

End Function

 

Public Function MakePropertyValue(ByVal cName As String, ByVal uValue As Object) As Object

        Dim oStruct As Object

        oStruct = oServiceManager.Bridge_GetStruct("com.sun.star.beans.PropertyValue")

        oStruct.Name = cName

        oStruct.Value = uValue

        MakePropertyValue = oStruct

End Function

 

Sub CellulePolice()

        oDocument = oDocument.CurrentController.Frame

       

        Dim Arguments(4) As Object

        oSel = oDocument.CurrentController.Frame

        Arguments(0) = MakePropertyValue("CharFontName.StyleName", "")

        Arguments(1) = MakePropertyValue("CharFontName.Pitch", 2)

        Arguments(2) = MakePropertyValue("CharFontName.CharSet", -1)

        Arguments(3) = MakePropertyValue("CharFontName.Family", 5)

        Arguments(4) = MakePropertyValue("CharFontName.FamilyName", "Arial Rounded MT Bold")

 

 

        oDispatcher.executeDispatch(oSel, ".uno:CharFontName", "", 0, Arguments)

 

 

End Sub

 

 

Répondre à