Yes. I'll merge some of your suggestions into my code re. the cursor.

The loop isn't necessary however. As I understand it (and as seems to be happening when I test it), the Print Document event happens once per letter print (i.e. for each row in the database) and I only want to insert one text "Attn:" per print. I suspect I will have to remove it for the next letter printed though! This is a twist I hadn't thought of - that I actually was modifying the original document and not just the version sent to print. :) It will make the code a touch more complicated.

Thanks again.


Andrew Douglas Pitonyak wrote:
Gary,

1. Do you now have the complete solution that I created for you?

2. I will go back and inspect the "found" object, I did not think that it was a cursor. You could be correct.

3. The thing about "hijacking" a thread. Well, I found out about that on this list myself. It works like this (well, I only kind of understand it)...

Every message has some sort of unique identifier.
When I reply to a message, the unique identifier is somehow included, so an email client knows that the message is a reply from the other message. The nice thing about this is that I can view my messages in a "threaded" view, which groups all of the replies to a message together.

"Hijacking" a thread means that you start a new thread (topic) by replying to a message that is not related to your topic rather than creating an entirely new message. I used to do this because it was faster than entering the mailing address in the To line. After I found out about viewing threads, I can now see the problem myself.

Gary Dale wrote:
Sorry Andrew, your answer got lost in all the noise in this group (like NoOp's strange complaint that I hijacked a thread).

Your answer confused me a bit when you said I don't have a Cursor but a text range. I noticed that, indeed, I had a range selected (the string the search found), which is why I changed the setString() to include the selected text. However, OOo does call it a TextCursor - even if of the SwX kind. :)

Thanks for your help!


Andrew Douglas Pitonyak wrote:
I answered this question in full on 7/1/07 (yesterday).
I forwarded the complete answer in another message just moments ago (since perhaps Gary is not subscribed).

Gary Dale wrote:
This code almost works. It appears that the programmers manual's example is bad. I just have to reposition the text cursor to after the "Attn:" before inserting the paragraph_break.
Yes, this is only because you chose to use setString() on the cursor (well,you set the property, which is about the same thing).

However, it appears that findFirst returns a null if the search fails. Quick question: How do I test for a null?
IsNull(variable_name)


Sub Main
   Dim Doc         As Object     Dim Cursor         As Object
   Dim SearchDesc    As Object
   Doc         = ThisComponent
   SearchDesc    = Doc.createSearchDescriptor()
   SearchDesc.searchString            = "Dear"
   SearchDesc.searchCaseSensitive    = True
   SearchDesc.searchWords            = True
   SearchDesc.searchSimilarity        = False
   Cursor     = Doc.findFirst(SearchDesc)
Be careful here, you do not really have a cursor. It is a text range, but it is not a cursor.
   IF (Cursor.String = SearchDesc.searchString) THEN
       Cursor.String = "Attn:" + Cursor.String
Doc.Text.insertControlCharacter(Cursor, com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, False)
   END IF
End Sub

Gary Dale wrote:
One clue that I've just found is the the BASIC Programmer's Guide is wrong. Page 121 clearly shows findFirst returning a boolean but in fact it returns an SwXTextCursor!

What I'm confused about however is the SwXTextCursor contains a String property but it also contains a Text property which contains a String - and the two strings are different! One contains the search string while the other contains some text from the start of the document.


Gary Dale wrote:
If I run the code below, I get a "BASIC runtime error. Incorrect property value." on the "IF Found THEN" line.

If I remove the REMs from the "Option Explicit" and "DIM Found" lines, the error moves up one line.

If I replace the "Doc = ThisComponent" line with "Doc = StarDesktop.CurrentComponent", I get a "BASIC runtime error. Property or method not found" on the "SearchDesc = Doc.createSearchDescriptor()" line.

This code is attached to an OpenOffice.org Writer form letter and is triggered by the Print Document event. Somehow it looks like ThisComponent is something other than what all the examples I've seen say it should be. Can anyone see what I'm doing wrong or suggest a method of debugging it?


REM  *****  BASIC                           *****
REM  *****  insert "Attn:" line when needed *****
REM  ********************************************
REM Option Explicit
Sub Main
   Dim Doc         As Object     Dim Cursor         As Object
   Dim SearchDesc    As Object
REM    Dim    Found        As    Boolean
   Doc         = ThisComponent
   SearchDesc    = Doc.createSearchDescriptor()
   SearchDesc.searchString            = "Dear"
   SearchDesc.searchCaseSensitive    = True
   SearchDesc.searchWords            = True
   SearchDesc.searchSimilarity        = False
   Found         = Doc.findFirst(SearchDesc)
   IF Found THEN
       Cursor    = Doc.Text.createTextCursor
       IF NOT isStartOfSentence() THEN
           gotoStartOfSentence(FALSE)
       END IF
       Cursor.String = "Attn:"
Doc.Text.insertControlCharacter(Cursor, com.sun.star.text.ControlCharacter.PARAGRAPH_BREAK, False)
   END IF
End Sub

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to