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]