Page 1 of 1

[Solved] Problem on VB.net and chart

Posted: Fri Dec 14, 2012 1:00 am
by keosge
I'm trying to add a chart to a calc new file, but when i try to do, it give me this error: [automation bridge] unexpected exception in UnoConversionUtilities<T>::variantToAny !
at line Charts.addNewByName("MyChart", Rect, RangeAddress, False, False).

this is the code

Code: Select all

        Dim Doc As Object
        Dim Charts As Object
        Dim Chart As Object
        Dim Rect As New unoidl.com.sun.star.awt.Rectangle
        Dim RangeAddress(0) As Object

        Url = "private:factory/scalc"

        oSM = CreateObject("com.sun.star.ServiceManager")
        odp = oSM.createInstance("com.sun.star.frame.Desktop")
        odc = odp.loadComponentFromURL(Url, "_blank", 0, aNoArgs)
        oss = odc.Sheets(0)
        os = oss.getByIndex(0)

        Dim OpenPar(1) As Object

        dispatch = oSM.createInstance("com.sun.star.frame.DispatchHelper")



        'RangeAddress(0) = New unoidl.com.sun.star.table.CellRangeAddress
        RangeAddress(0) = oSM.Bridge_GetStruct("com.sun.star.table.CellRangeAddress")
        Charts = os.charts
        Rect.X = 8000
        Rect.Y = 1000
        Rect.Width = 10000
        Rect.Height = 7000
        RangeAddress(0).Sheet = 0
        RangeAddress(0).StartColumn = 1
        RangeAddress(0).StartRow = 3
        RangeAddress(0).EndColumn = 1
        RangeAddress(0).EndRow = 13



        Dim oMRI As Object
        oMRI = oSM.createInstance("mytools.Mri")
        oMRI.inspect(Charts)

        Charts.addNewByName("MyChart", Rect, RangeAddress, False, False)
can some body help me?

Re: Problem on VB.net and chart

Posted: Fri Dec 14, 2012 2:19 am
by Charlie Young
I think it doesn't like

Code: Select all

Dim Rect As New unoidl.com.sun.star.awt.Rectangle
though there may be some trick for getting that to work.

You should be able to fix it with

Code: Select all

Dim Rect As Object

...

Rect = oSM.Bridge_GetStruct("com.sun.star.awt.Rectangle")

Re: Problem on VB.net and chart

Posted: Fri Dec 14, 2012 6:10 am
by FJCC
Charlie is correct. This works for me.

Code: Select all

Sub MakeChart()
Dim Doc As Object
        Dim Charts As Object
        Dim Chart As Object
        Dim RangeAddress(0) As Object

        URL = "private:factory/scalc"

        Set oSM = CreateObject("com.sun.star.ServiceManager")
        Set odp = oSM.createInstance("com.sun.star.frame.Desktop")
        Set odc = odp.loadComponentFromURL(URL, "_blank", 0, Array())
        Set oss = odc.Sheets(0)
        Set os = oss.getByIndex(0)

        Dim OpenPar(1) As Object
        
        Set Rect = oSM.Bridge_GetStruct("com.sun.star.awt.Rectangle")

        Set RangeAddress(0) = oSM.Bridge_GetStruct("com.sun.star.table.CellRangeAddress")
        Set Charts = os.Charts
        Rect.X = 8000
        Rect.Y = 1000
        Rect.Width = 10000
        Rect.Height = 7000
        RangeAddress(0).Sheet = 0
        RangeAddress(0).StartColumn = 1
        RangeAddress(0).StartRow = 3
        RangeAddress(0).EndColumn = 1
        RangeAddress(0).EndRow = 13

        'Dim oMRI As Object
        'oMRI = oSM.createInstance("mytools.Mri")
        ' oMRI.Inspect (Charts)

        Charts.addNewByName "MyChart", Rect, RangeAddress, False, False
End Sub

Re: Problem on VB.net and chart

Posted: Fri Dec 14, 2012 5:45 pm
by keosge
Thank a lot,

the correct it's that

Rect = oSM.Bridge_GetStruct("com.sun.star.awt.Rectangle")

i solved it