Issue in dynamic table

I am trying to create a table using the below code:


Sub CreateTable

Dim sess As New NotesSession

Dim ws As New NotesUIWorkspace

Dim db As NotesDatabase

Dim doc,docNew As NotesDocument

Dim docColl As NotesDocumentCollection



Dim rti As NotesRichTextItem	

Dim rtnav As NotesRichTextNavigator

Dim rtt As NotesRichTextTable

Dim rtsTableHeader As NotesRichTextStyle

Dim rtsTableRow As NotesRichTextStyle



Dim TableData(5) As String

Dim Header(5) As String

Dim Count As Integer	

Dim rtpsCols(4) As NotesRichTextParagraphStyle



Set db = sess.CurrentDatabase

Set docNew= db.CreateDocument

docNew.Form= "testingtable"

Set docColl = db.AllDocuments

Call ws.EditDocument(True, docNew)



If docColl.Count > 0 Then		

	Header(0) = "Header 1"

	Header(1) = "Header 2"

	Header(2) = "Header 3"

	Header(3) = "Header 4"

	Header(4) = "Header 5"

	

	TableData(0) = "Column 1"

	TableData(1) = "Column 2"

	TableData(2) = "Column 3"

	TableData(3) = "Column 4"

	TableData(4) = "Column 5"

	

	Set rtsTableHeader = sess.CreateRichTextStyle 'Setting header text properties

	rtsTableHeader.FontSize = 10 

	rtsTableHeader.Bold = True

	rtsTableHeader.NotesColor=Color_RED

	

	Set rtsTableRow= sess.CreateRichTextStyle  'Setting data/columns text properties

	rtsTableRow.FontSize = 8		

	rtsTableRow.NotesColor=Color_Black

	rtsTableRow.Bold = False

	

	Set rtpsCols(0) = sess.CreateRichTextParagraphStyle

	rtpsCols(0).Alignment =3

	rtpsCols(0).Firstlineleftmargin = 0

	rtpsCols(0).Leftmargin = 0

	rtpsCols(0).RightMargin = RULER_ONE_CENTIMETER * 3  

	

	Set rtpsCols(1) = sess.CreateRichTextParagraphStyle

	rtpsCols(1).Alignment =1

	rtpsCols(1).Firstlineleftmargin = 0

	rtpsCols(1).Leftmargin = 0

	rtpsCols(1).RightMargin = RULER_ONE_CENTIMETER * 2

	

	Set rtpsCols(2) = sess.CreateRichTextParagraphStyle

	rtpsCols(2).Alignment =2  

	rtpsCols(2).Firstlineleftmargin = 0

	rtpsCols(2).Leftmargin = 0

	rtpsCols(2).RightMargin = RULER_ONE_CENTIMETER *2		

	

	Set rtpsCols(3) = sess.CreateRichTextParagraphStyle

	rtpsCols(3).Alignment =2

	rtpsCols(3).Firstlineleftmargin = 0

	rtpsCols(3).Leftmargin = 0

	rtpsCols(3).RightMargin = RULER_ONE_CENTIMETER * 2

	

	Set rtpsCols(4) = sess.CreateRichTextParagraphStyle

	rtpsCols(4).Alignment =0

	rtpsCols(4).Firstlineleftmargin = 0

	rtpsCols(4).Leftmargin = 0

	rtpsCols(4).RightMargin = RULER_ONE_CENTIMETER * 2

	

	

	Set doc = docColl.GetFirstDocument

	While Not doc Is Nothing

		

		Set rti = doc.GetFirstItem("Body")

		

		rtsTableHeader.NotesFont = rti.GetNotesFont ("Arial", True)

		rtsTableRow.NotesFont = rti.GetNotesFont("Arial", True)			

		

		Call rti.AppendTable(1,5,"",250, rtpsCols)

		Call doc.Save(True,False)			

		Set rtnav = rti.CreateNavigator

		Set rtt = rtnav.GetFirstElement(RTELEM_TYPE_TABLE)

		

		Call rti.AppendStyle(rtsTableHeader)			

		Call rtnav.FindFirstElement (RTELEM_TYPE_TABLECELL) 

		For iCol = 1 To 5 'Step 1

			Call rti.BeginInsert(rtnav)

			Call rti.AppendText(Header(iCol-1))

			Call rti.EndInsert

			Call rtnav.FindNextElement (RTELEM_TYPE_TABLECELL)

		Next

		Call rti.AppendStyle(rtsTableRow)

		For m=1 To 5

			Call rtt.AddRow

			Call rtnav.FindNextElement (RTELEM_TYPE_TABLECELL)

			For Count=0 To 4 		

				Call rti.BeginInsert(rtnav)

				Call rti.AppendText(TableData(Count))

				Call rti.EndInsert

				Call rtnav.FindNextElement (RTELEM_TYPE_TABLECELL)

			Next

		Next

		

		Call doc.Save(True,False)

		Set doc = docColl.GetNextDocument(doc)

	Wend

End If



'Call docNew.Save( True, True )

End Sub


As u can see above i m using the code

Set rtpsCols(0) = sess.CreateRichTextParagraphStyle

rtpsCols(0).Alignment =3

rtpsCols(0).Firstlineleftmargin = 0

rtpsCols(0).Leftmargin = 0

rtpsCols(0).RightMargin = RULER_ONE_CENTIMETER * 3

multiple number of times hencei tried using a for loop for doing this but in doing so it giving me an error… Is it not possible to set RichTextParagraphStyle array in loop?

Subject: Issue in dynamic table

You can set a RichTextParagraphStyle object and it’s properties in a for loop.

Here’s how:

Dim vTableData, i%

Dim rtpsCols(4) As NotesRichTextParagraphStyle

vTableData = Split(|Column 1,Column 2,Column 3,Column 4,Column 5|, |,|)

For i = Lbound(vTableData) To Ubound(vTableData)

Set rtpsCols(i) = sess.CreateRichTextParagraphStyle

rtpsCols(i).Firstlineleftmargin = 0

rtpsCols(i).Leftmargin = 0

If i = 0 Then

rtpsCols(i).Alignment =3

rtpsCols(i).RightMargin = RULER_ONE_CENTIMETER * 3

Else

rtpsCols(i).Alignment =1

rtpsCols(i).RightMargin = RULER_ONE_CENTIMETER * 2

End If

Next

HTH

Adi

Subject: RE: Issue in dynamic table

Is it necessary that number of columns should be equal to the size of array…

Subject: RE: Issue in dynamic table

I think so, because you’re using these styles as a param for AppendTable method of RichText item. If you don’t want to set the style for a column, you can exclude it in the ForLoop. So that column will get default Style.

Try it on your own.

Hth

Adi

Subject: Issue in dynamic table

Help us out here. On what line of code does the error occur and what EXACTLY is the error message.