I have a problem building a table in LotusScript and displaying it through a browser. When I create a table in a Richtextitem using Appendtable without style parameters and display it through a browser all works fine. But when I add a style array (last parameter of Appendtable) nothing displays and in actual fact the agent that builds the table stops executing. I have build the style array as per many examples I’ve seen on the web. What is wrong?
Subject: RE: Appendtable with richtext style problem
Your question is missing a lot of important information (a hint: source code, and what does “agent stops executing” mean?), and you also have apparently not debugged the application yourself to see why it is failing. See “crispy” link below for details of what information you might want to include.
- Andre Guirard, IBM/Lotus Development
Useful blog: Best Practice Makes Perfect
For faster answers, be C R I S P Y
Subject: RE: Appendtable with richtext style problem
Sorry Andre - I created my post from home so did not have the source code available. Here it is:
Sub Initialize
Dim session As New NotesSession
Dim db As NotesDatabase
Dim doc1 As NotesDocument
Dim rtitem As NotesRichTextItem
Dim richStyle As NotesRichTextStyle
Dim nam As NotesName
Dim count As Integer
Set db = session.CurrentDatabase
Dim dateTime As New NotesDateTime( "03/14/95" )
Dim selection As String
Dim collection As NotesDocumentCollection
selection = "@Contains( Subject; ""407"" )"
Set collection = db.Search( selection, dateTime, 0 )
Set doc1 = session.DocumentContext
Set rtitem = New NotesRichTextItem ( doc1, "Body" )
Set richStyle = session.CreateRichTextStyle
richStyle.NotesFont = rtitem.GetNotesFont("Arial", True)
richStyle.FontSize = 6
richStyle.Bold = True
Call rtitem.AppendStyle(richStyle)
Const RULER_ONE_INCH = 1440
Dim arrStyles(0 To 3) As NotesRichTextParagraphStyle
Set arrStyles(0) = session.CreateRichTextParagraphStyle
Set arrStyles(1) = session.CreateRichTextParagraphStyle
Set arrStyles(2) = session.CreateRichTextParagraphStyle
With arrStyles(0)
Call .ClearAllTabs()
.LeftMargin = RULER_ONE_INCH * 0.375
.FirstLineLeftMargin = RULER_ONE_INCH * 0.375
.RightMargin = RULER_ONE_INCH * 2
.Alignment = ALIGN_LEFT
End With
With arrStyles(1)
Call .ClearAllTabs()
.LeftMargin = RULER_ONE_INCH * 0.375
.FirstLineLeftMargin = RULER_ONE_INCH * 0.375
.RightMargin = RULER_ONE_INCH * 2
.Alignment = ALIGN_LEFT
End With
With arrStyles(2)
Call .ClearAllTabs()
.LeftMargin = RULER_ONE_INCH * 0.375
.FirstLineLeftMargin = RULER_ONE_INCH * 0.375
.RightMargin = RULER_ONE_INCH * 2
.Alignment = ALIGN_LEFT
End With
Call rtitem.AppendTable(collection.Count, 3,,RULER_ONE_INCH * 0.0125, arrStyles )
Dim rtnav As NotesRichTextNavigator
Set rtnav = rtitem.CreateNavigator
Call rtnav.FindFirstElement(RTELEM_TYPE_TABLECELL)
count = 0
Set doc = collection.GetFirstDocument
While Not doc Is Nothing
Call rtitem.BeginInsert(rtnav)
Call rtitem.AppendDocLink( doc, doc.Subject(0), doc.Subject(0) )
Call rtitem.EndInsert
Call rtnav.FindNextElement(RTELEM_TYPE_TABLECELL)
Set nam = New NotesName( doc.From(0) )
Call rtitem.BeginInsert(rtnav)
Call rtitem.AppendText(nam.Common)
Call rtitem.EndInsert
Call rtnav.FindNextElement(RTELEM_TYPE_TABLECELL)
Call rtitem.BeginInsert(rtnav)
Call rtitem.AppendText(Cstr(doc.PostedDate(0)))
Call rtitem.EndInsert
count=count+1
If count < collection.Count Then
Call rtnav.FindNextElement(RTELEM_TYPE_TABLECELL)
End If
Set doc = collection.GetNextDocument(doc)
Wend
doc1.Query = Cstr(count)
End Sub
This code runs from an agent that is called by a WebQueryOpen event in a form that is displayed through a browser. Basically, this agent gets a number of documents and displays them in a table on the calling form.
The reason i’m saying that the agent stops running is that the line ‘doc1.Query = Cstr(count)’ which populates the field ‘Query’ in the form with the number of documents found doesn’t wseem to be reached. This field is populated fine when I ran the agent without the Styles parameter, but not with it.
Hope this is enough info.
By the way, how can I debug my code through a browser?
Subject: Found it - Appendtable with richtext style problem
Rather bizarre, but the Style array needs to start at index position 0, so instead of declaring and filling the array as:
Dim arrStyles(1 to 3) As NotesRichTextParagraphStyle
Set arrStyles(1) = session.CreateRichTextParagraphStyle
Set arrStyles(2) = session.CreateRichTextParagraphStyle
Set arrStyles(3) = session.CreateRichTextParagraphStyle
it needs to be defined as:
Dim arrStyles(2) As NotesRichTextParagraphStyle
Set arrStyles(0) = session.CreateRichTextParagraphStyle
Set arrStyles(1) = session.CreateRichTextParagraphStyle
Set arrStyles(2) = session.CreateRichTextParagraphStyle
Subject: RE: Found it - Appendtable with richtext style problem
A few points:The second argument to db.Search is normally Nothing. It’s not as efficient to specify a date which you know is earlier than everything in the database.
It’s not necessary to use the statement Const RULER_ONE_INCH = 1440 because this is a built-in constant.
Based on my testing, an array with starting index 1 works just fine. It’s just that the array needs to have as many elements as you have columns, and you need to assign all the array elements. Originally you defined it (0 to 3) and then only assigned three elements and created three columns. (1 to 3) works OK.
You can’t directly debug Querysave agents, that I know of, but the debugging article, a link to which is in the CRISPY document I linked you to before, gives techniques for doing this.
Subject: RE: Found it - Appendtable with richtext style problem
Thanks for the suggestions Andre. Your absolutely right - I hadn’t noticed that I declared more array elements than I used (trees, woods that sort of thing
).
Gerrit