Basic code not running on VB

The Application Programming Interface and the OASIS Open Document Format

Basic code not running on VB

Postby YUJIN » Fri Aug 08, 2014 10:06 am

Hello Everyone,
Greetings!
I have one request which need to create&work on OOo writer with VB6. And I run into problems which I tried and searched for answer for days but got no answer.
Hope somebody can help to check it out. Thanks!

Here is the problem:
I have a piece of code which run fine under OOo Basic, however when I tried it in VB6. it failed when running ThisComponent.getChapterNumberingRules with message 438:Object Doesn't Support this Property or Method

Here is the code in OOo Basic(from Andrew's macro):
Code: Select all   Expand viewCollapse view
sub Main
    Dim i%, j%
    Dim oRules
    Dim oRule()
    Dim oProp
    oRules = ThisComponent.getChapterNumberingRules()
    'msgbox oRules.getCount()
    For i = 0 To oRules.getCount() - 1
    oRule() = oRules.getByIndex(i)
   
    'debug.print LBound(oRule())
    REM I do not set the following:
    REM Adjust, StartWith, LeftMargin,
    REM SymbolTextDistance, FirstLineOffset
    For j = LBound(oRule()) To Ubound(oRule())
    REM oProp is only a copy of the property.
    REM You must assign the property back into the array.
    oProp = oRule(j)
   ' msgbox   oProp.name
   
    Select Case oProp.Name
    ' Case "ParagraphStyle"
    ' val = "Heading" & i
    ' oProp.Value = "Heading" & i
    Case "HeadingStyleName"
    ' val = "Heading" & i
    ' oProp.Value = "Heading" & i
    Case "NumberingType"
    oProp.Value = com.sun.star.style.NumberingType.ARABIC
    Case "ParentNumbering"
    oProp.Value = i + 1
    Case "Prefix"
    oProp.Value = ""
    Case "Suffix"
    oProp.Value = "."
    'Case "CharStyleName"
    ' oProp.Value =
    End Select
    oRule(j) = oProp
    Next
    oRules.replaceByIndex(i, oRule())
    Next
end sub



Here is the code I converted for VB:
Code: Select all   Expand viewCollapse view
sub Main
    Dim i%, j%
    Dim oRules
    Dim oRule()
    Dim oProp
   Dim oSM,oDesk
   
   Dim arg() 
   Dim ThisComponent
   Set oSM = CreateObject("com.sun.star.ServiceManager")
    Set oDesk = oSM.createInstance("com.sun.star.frame.Desktop")
   oUrl = "private:factory/swriter"
    Set oDoc = oDesk.loadComponentFromURL(oUrl, "_blank", 0, arg())   
   Set ThisComponent = oDesk.getCurrentComponent()
   
    oRules = ThisComponent.getChapterNumberingRules()
    'msgbox oRules.getCount()
    For i = 0 To oRules.getCount() - 1
    oRule() = oRules.getByIndex(i)
   
    'debug.print LBound(oRule())
    REM I do not set the following:
    REM Adjust, StartWith, LeftMargin,
    REM SymbolTextDistance, FirstLineOffset
    For j = LBound(oRule()) To Ubound(oRule())
    REM oProp is only a copy of the property.
    REM You must assign the property back into the array.
    oProp = oRule(j)
   ' msgbox   oProp.name
   
    Select Case oProp.Name
    ' Case "ParagraphStyle"
    ' val = "Heading" & i
    ' oProp.Value = "Heading" & i
    Case "HeadingStyleName"
    ' val = "Heading" & i
    ' oProp.Value = "Heading" & i
    Case "NumberingType"
    oProp.Value = com.sun.star.style.NumberingType.ARABIC
    Case "ParentNumbering"
    oProp.Value = i + 1
    Case "Prefix"
    oProp.Value = ""
    Case "Suffix"
    oProp.Value = "."
    'Case "CharStyleName"
    ' oProp.Value =
    End Select
    oRule(j) = oProp
    Next
    oRules.replaceByIndex(i, oRule())
    Next
end sub


Most of the code is same, expect :
Code: Select all   Expand viewCollapse view
   Dim oSM,oDesk
   
   Dim arg() 
   Dim ThisComponent
   Set oSM = CreateObject("com.sun.star.ServiceManager")
    Set oDesk = oSM.createInstance("com.sun.star.frame.Desktop")
   oUrl = "private:factory/swriter"
    Set oDoc = oDesk.loadComponentFromURL(oUrl, "_blank", 0, arg())   
   Set ThisComponent = oDesk.getCurrentComponent()


I realized ThisComponent in VB code maybe different with Basic one, and looking at the introduction to getChapterNumberingRules at http://www.openoffice.org/api/docs/common/ref/com/sun/star/text/XChapterNumberingSupplier.html#getChapterNumberingRules I think I will need to access getChapterNumberingRules through interface XChapterNumberingSupplier. However I am don't know how to access this interface, can somebody show me an example please?

Another request is can someone explain what is the different between the OOo Basic ThisComponent and the one I created in VB6? and why ThisComponent.getChapterNumberingRules not working in VB6?

Thank you very much for your help and support!
OpenOffice 4.1 on Windows 7.
YUJIN
 
Posts: 1
Joined: Thu Aug 07, 2014 7:49 am

Return to UNO API and ODF

Who is online

Users browsing this forum: No registered users and 2 guests