Writer macro "setpropertyvalue" question

I’m trying to write a macro to insert index entries. I found one that does it nicely, but now I need to specify the outline level of the entry. I came across the following line to do that:

xEntry.setPropertyValue ( “Level”, new Short ( (short) 1 ) );

But that line keeps returning “parenthesis mismatch”, with the text xEntry.setPropertyValue ( “Level”, new Short highlighted.

Does anyone have a clue how to spec the entry level? I would also like to update only a certain ToC rather than all ToCs in the doc.

I tried to enter the Macro code here, but it would not format properly, so it is at http://pastebin.com/U5bzac6D.

Thanks much.

Basic? So, may be simple xEntry.setPropertyValue ( "Level", 1) ? (without “new” and semicolons)
This is only my assumption, for accurate analysis need a bigger piece of code

Yes, I think it’s Basic. Using that line brings BASIC runtime error. Object variable not set.

I will add the code to the question. Thanks.

The setPropertyValue method is called with 2 parameters as it is specified for.
There are two points of doubt:

  1. The second parameter position is containing new Short ( (short) 1 ) . I do not know a example of that syntax, surely not in BASIC. Basic does not even know a type ‘Short’ (short integer?)
  2. After the quoted statement there comes a semicolon in the position of a statement delimiter. BASIC does not accept this. Its statement delimiter is either the colon followed by a space (not often used) or the line break.
    Therefore I suspect that line of code to have wrongly be placed inside a BASIC routine. In a specific context of another programming tool the mentioned usage of ‘new’ may be allowed (and possibly even make sense).
    I would expect the statement xEntry.Level = 1 should do in BASIC.

Thanks for your response. The semicolon was in the statement as found on the web, but I tried it with and without, as none of the rest of the statements have it. I tried your statement in lieu of the original, and it brought the BASIC runtime error. Object variable not set. error.

This obviously means that the variable (name ‘xEntry’) did not get a valid object assigned in advance of the arttempt to execute the statement. I cannot tell anything more about the problem as long as I do not knoww anything about the code this single statement is embedded in. Debugging may be possible for programs. It surely is not for isolated statements. I also cannot understand the Sub code you linked to. It seems incomplete at least.

Ok, after a lot of playing around I think I have it. The line I needed is

oIndex.setPropertyValue ( “Level”, 4)

I changed the xIndex to oIndex, in keeping with the rest of the code. Then I simplified the parameters to be “parameter”, value. It seems to be working.

The working macro is at http://pastebin.com/MPWbEPBd

(I’m not sure why multiple lines of code are not formatted properly on this site).

Now I will try to figure out how to update only a specific Index.

Thanks for all the help.

EDIT: Actually, I’m getting buggy performance from that line. It worked fine yesterday, but today I consistently get one level higher than what I set.

(Edited by @Lupp:slight_smile: To insert multiline code you need:

  1. A blank line between the preceding text and the code.

  2. 4 contiguous spaces prefixed to each line of code as a syntactical indicator.
    (I won’t comment on the Sub itself. I just quote it as an example for the usage of the above guide.)

    Sub SetIndex
    ’ see: Indexes and Index Marks - Apache OpenOffice Wiki
    oSelection = ThisComponent.CurrentController.Selection
    oIndex =ThisComponent.createInstance(“com.sun.star.text.ContentIndexMark”)
    oIndex.setPropertyValue ( “Level”, 4)
    for Int1 = 0 to oSelection.Count -1
    oSel1 = oSelection (Int1)
    if HasUnoInterfaces(oSel1,“com.sun.star.text.XTextRange”) Then
    ThisComponent.Text.InsertTextContent(oSel1, oIndex, True)
    end If
    Next Int1
    Update_Index 'Call Sub Update_Index
    End Sub

Thanks Lupp.

BTW, it doesn’t look like updating a specific ToC is possible, according to the parameters I found online. Unless parameters have been added in the past few years.