Notes Rich Text Range: Problem with TextRun

I hope someone can help - I’m going mad! Here is wot I am trying to achieve - it’s simple but I just cannot get it to work: I have a RT field on a document containing string text only. Wherever there is a string of colour red, I am simply, at the moment, trying to change it’s colour to, say, blue.

Below is some code whereby I first create a RT Navigator to the rt field on the document. I then create 2 ranges: One which I set at paragraph level and the other at text run level within the paragraph. The darn thing just does not work! Is it my coding is it a bug with navigators/ranges??

Anyhelp greatly appreciated.

Sub Click(Source As Button)

Dim uiws As New notesuiworkspace

Dim session As New NotesSession

Dim db As NotesDatabase

Dim view As notesview

Dim rtitem1 As NotesRichTextItem

Dim doc As NotesDocument

Dim rtnav1 As NotesRichTextNavigator

Dim style1 As NotesRichTextStyle

Dim rtnavPara As NotesRichTextNavigator

Dim rtrangePara As NotesRichTextRange

Dim rtrangeRun As NotesRichTextRange

Dim paraCount As Integer

Dim runCount As Integer



Set db = session.CurrentDatabase

Set view = db.GetView("testdocs")

Set doc = view.GetFirstDocument

Set rtitem1 = doc.GetFirstItem("body")

Set rtnav1 = rtitem1.CreateNavigator



If rtnav1.FindFirstElement(RTELEM_TYPE_TEXTPARAGRAPH) Then

	

	Set rtrangePara = rtitem1.CreateRange

	Set rtrangeRun = rtitem1.CreateRange

	

	Do

		paraCount = paraCount + 1

		runCount = 0

		Call rtrangePara.SetBegin(rtnav1)

		Call rtrangePara.SetEnd(rtnav1)

		Set rtnavPara = rtrangePara.Navigator		

		

		Call rtnavPara.FindFirstElement(RTELEM_TYPE_TEXTRUN)

		

		Do

			runCount = runCount + 1

			Call rtrangeRun.SetBegin(rtnavPara)

			Call rtrangeRun.SetEnd(rtnavPara)

			

			Set style1 = rtrangeRun.Style

			

			If style1.NotesColor = COLOR_RED Then

				

					

				oldstring = rtrangerun.TextParagraph

				style1.NotesColor = COLOR_BLUE

				Call rtrangerun.SetStyle(style1)

				Call rtrangerun.FindandReplace(oldstring,rtrangerun.TextParagraph,1+2+4)

				Call doc.Save(True, False)



			

				'reset nav positions: 

'go back to first para in rt field.

'now find para that contained red text and recreate a navigator pointing to it - this bit is ok.

				If rtnav1.FindFirstElement(RTELEM_TYPE_TEXTPARAGRAPH) Then

					If rtnav1.FindnthElement(RTELEM_TYPE_TEXTPARAGRAPH, paracount) Then

						Set rtrangePara = rtitem1.CreateRange

						Call rtrangePara.SetBegin(rtnav1)

						Call rtrangePara.SetEnd(rtnav1)

						Set rtnavPara = rtrangePara.Navigator		

					End If

				End If	

				

				'now find the next text run AFTER the red text run

				

				Set rtrangeRun = rtitem1.CreateRange

				

				If rtnavpara.FindFirstElement(RTELEM_TYPE_TEXTRUN) Then

					If rtnavPara.FindnthElement(RTELEM_TYPE_TEXTRUN,runcount)  Then

						Call rtrangeRun.SetBegin(rtnavPara)

						Call rtrangeRun.SetEnd(rtnavPara)

					End If

				End If

				

				

				

				

				

			End If

			

		Loop While rtnavPara.FindNextElement(RTELEM_TYPE_TEXTRUN)

		

	Loop While rtnav1.FindNextElement(RTELEM_TYPE_TEXTPARAGRAPH)

	

End If

End Sub

Subject: Notes Rich Text Range: Problem with TextRun

Just started fiddling with this… I created newstyle.NotesColor = NewColor,

Using your style1

Set Style1 = rtrange.Style

			If style1.Notescolor = Color_black Then

				Call rtrange.SetStyle(newStyle)

				changed = True

			End If

if changed, save the form, close and reopen uidoc.

Still working on highlighting a word…:slight_smile:

Subject: RE: Notes Rich Text Range: Problem with TextRun

Thanks Marilyn. My code does a lookup to a view to find the doc containing the RT field and then tries to process the text so does not use the uidoc.

The code will eventually be run as part of a querysave event on a form presented to the user in a browser.

Thanks for your help - anymore wouldbe great!..:o)