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]