Beware the Help Database Examples

Compare these 2 examples (only slightly modified) from the ND6 App Dev Help:

Example 1:

If Not rtnav.GetFirstElement(RTELEM_TYPE_DOCLINK) Then

Messagebox "No doclinks in Body item",, "No doclinks"

Exit Sub

End If

Example 2:

If Not rtnav.FindFirstElement(RTELEM_TYPE_DOCLINK) Then

Messagebox "No doclinks in Body item",, "No doclinks"

Exit Sub

End If

Look the same, yes? Except that GetFirstElement returns an Element (in this case a NotesRichTextDocLink object) and FindFirstElement returns a Boolean.

I spent an hour or so trying to get CreateNavigator to work in my code to get the properties of a doclink. I had copied the first example from the Help database into my code, modifying the condition by removing the “Not”. It didn’t work because an Element is Not a Boolean.

Okay, if I’d read the full documentation on GetFirstElement, I’d have known that it didn’t return a Boolean. But if the example condition had been “If Not (rtnav.GetFirstElement(RTELEM_TYPE_DOCLINK) Is Nothing) Then”, then my code would have worked.

My point is, beware the Help database examples. They’re not always shining examples of code. Oh, and always read the full documentation … and check the developer forum.

Regards,

Robert Fairhead

robertf@rocher.com.au

Subject: Errors in NotesRichTextDoclink, NotesRichTextSection, and NotesRichTextTable

This problem is SPR’d and release noted (small consolation if you’re just grabbing sample code from help). Not sure how this happened - we try to copy-and-paste tested code into the source doc. Sorry for the confusion. Here’s the text of the release note.

NotesRichTextDoclink, Section, and Table examples

Applies to:

Chapter

Section

SPR #

: 04 Documentation updates

: 11 Domino Designer Programming Guide

: JFEN5EAPGV

Release Note Text:

Many of the examples for NotesRichTextDoclink, NotesRichTextSection, and NotesRichTextTable contain one of the following lines of incorrect code:

If Not rtnav.GetFirstElement(RTELEM_TYPE_DOCLINK) Then

If Not rtnav.GetFirstElement(RTELEM_TYPE_SECTION) Then

If Not rtnav.GetFirstElement(RTELEM_TYPE_TABLE) Then

The return value of GetFirstElement is an object and cannot be tested as a boolean.

Correct this code by substituting “Find” for “Get”:

If Not rtnav.FindFirstElement(RTELEM_TYPE_DOCLINK) Then

If Not rtnav.FindFirstElement(RTELEM_TYPE_SECTION) Then

If Not rtnav.FindFirstElement(RTELEM_TYPE_TABLE) Then

Ensure that the code contains a later line of code to get the object:

Set rtlink = rtnav.GetElement

Set rts = rtnav.GetElement

Set rtt = rtnav.GetElement

Subject: Errors in Help database SPR’d - thanks

Thanks, Robert. I much appreciated your response.

At least it’s taught me to read the full documentation and not just copy and paste the Help database examples in future!

Regards,

Robert Fairhead

robertf@rocher.com.au

PS. GetFirstElement & FindFirstElement from the NotesRichTextNavigator class & the NotesRichTextDocLink class are brilliant Notes 6 additions. Well done!