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]
--
Andrew Pitonyak
My Macro Document: http://www.pitonyak.org/AndrewMacro.odt
My Book: http://www.hentzenwerke.com/catalog/oome.htm
Info: http://www.pitonyak.org/oo.php
See Also: http://documentation.openoffice.org/HOW_TO/index.html
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]