NotesRichTextNavigator Question - Code included

I have a document saved with a rich text field. I am trying to use the rich text navigator to pick up and retain the formatted text for display on the web, via an agent.

Here is the code which I took from the help and modified for my own use:

Dim dc As NotesDocumentCollection

Dim body As NotesRichTextItem

Dim rtnav As NotesRichTextNavigator

Set session = New NotesSession

Set db = session.CurrentDatabase

Set dc = db.UnprocessedDocuments

Set doc = dc.GetFirstDocument

Set body = doc.GetFirstItem(“Details”)

Set rtnav = body.CreateNavigator

REM Get count of text paragraphs

count% = GetElementCount(rtnav, RTELEM_TYPE_TEXTPARAGRAPH)

msg$ = msg$ & “Text paragraphs:” & Chr(9) & count% & Chr(10)

REM Get count of text runs

count% = GetElementCount(rtnav, RTELEM_TYPE_TEXTRUN)

msg$ = msg$ & “Text runs:” & Chr(9) & Chr(9) & count% & Chr(10)

REM Display counts

Print msg$

Function GetElementCount(rtnav As NotesRichTextNavigator, eType As Integer) As Integer

GetElementCount = 0

If rtnav.FindFirstElement(eType) Then

Do

GetElementCount = GetElementCount + 1

Loop While rtnav.FindNextElement()

End If

End Function

The result indicate that there is nothing stored, when I know that there is:

Text paragraphs: 0 Text runs: 0

Is there something I am doing wrong? I am trying to break this task into pieces so I can better understand how it all works.

Any suggestions or ideas would be greatly appreciated. Thanks in advance.

Subject: NotesRichTextNavigator Question - Code included

I added error handling:

Print "Error in GetElementCount Function: " & Erl() & ": " & "Error# " & Err & ": " & Error ()

to the GetElementCount Function and I am getting the following error:

Error in GetElementCount Function: 6: Error# 91: Object variable not set

The error is occuring on the line:

If rtnav.FindFirstElement(eType) Then

I’m going to check out the error code, but if anyone has any ideas, I would love to hear them.

Thanks again.

Subject: NotesRichTextNavigator Question - Code included

This is one of those annoying little problems that crops up a lot. The problem is the rtnav has been set by a chain of references (session → database → document collection → document → rich text item → rich text navigator). Although you are passing rtnav into your function, it loses its identity because none of the references that make it valid are available. You have a choice: pass everything, or declare the variables in the chain in Globals so that they will be available inside your function as well.

Subject: RE: NotesRichTextNavigator Question - Code included

Thanks Stan - I will give it a try.

Once again - appreciate the help!

Subject: RE: NotesRichTextNavigator Question - Code included

I took the function and placed it in my main routine - not all that efficient, but at this point I am trying to learn my way around.

I am still a little confused though - the results are telling me that there is only one paragraph. However, when I entered the information I entered two paragraphs - using the ENTER key to seperate each.

Thanks Stan.

Subject: RE: NotesRichTextNavigator Question - Code included

That should come out right, provided that the Enter key was pressed in a rich text field. In the Notes client. Remember those “annoying little things”? Well, one of them is the fact that a rich text paragraph can contain line breaks, so it is entirely possible that you have two chunks of text that look for all the world like two paragraphs, but which are actually one. I believe I mentioned something about this being harder than it’s possible to imagine at first…

When in doubt, check for Chr(0), Chr(10) and Chr(13) within runs.

Subject: RE: NotesRichTextNavigator Question - Code included

Will do - Thanks!