Help with Redim preserve and CLear

I have a piece of code wherein I am using Redim Preserve and when I output the results, the print seems to exponentially grow.I know the problem is with the Redim preserve. How do I clear my array such that I do not lose the pointer reference? I guess I would need to do it before the WEND. Any help is much appreciated.

Set db=session.currentdatabase

Set curdoc=session.documentcontext

Dim UserName As New NotesName(session.effectiveusername)

Dim newitem$, reslist$, ulist As Variant



g_serverName=curdoc.Server_Name(0)

g_strPath = curdoc.DBPath(0)



On Error Goto errhandler



g_strPath = curdoc.db(0)

RepTypeTX = ReplaceSubString(Strright(curdoc.Query_String(0),"&RepType="),"%20"," ")



strPath = db.Filepath

For k% = 1 To Len(strpath)

	If Mid$(strpath,k%,1) = "\" Then

		Mid$(strpath,k%,1) = "/"

	End If

Next





Print |Content-Type:application/vnd.ms-excel| 

Print |Content-Disposition:Attachment; filename="Report.xls"|





Set view = db.GetView ( "AllCertTemplates" )

Set ATview = db.GetView("xAllCertTemplates2")



Set viewNav = view.CreateViewNav

Set viewEntry = viewNav.GetFirst

Call ReportHeaderAndColumnTitles

While Not ( viewEntry Is Nothing )

	If viewEntry.IsCategory = True Then

		

		Dim keys As String

		Dim templateList List As Boolean'

		keys =	Cstr(viewEntry.ColumnValues(0)) 

		

		Set vcollection = ATview.GetAllEntriesByKey(keys, True)

		If vcollection.count = 0 Then

			Print {<p><center>}

			Print {<table cellpadding=2 cellspacing=5 width=800>}

			Print {<tr><td class="TblCell" align=center valign=center><font class="Title">Checklist Activity Template(s) Report</font></td></tr>}

			Print {<tr><td align=center valign=center><font class="Title">No Documents Found</font></td></tr>}

			Print {</table>}

			Exit Sub

		End If

		

		Set Ventry = vcollection.GetFirstEntry()

		

		Dim x As Integer

		

		While Not (Ventry Is Nothing)

			

			Set DocTwo = Ventry.Document

	‘===========PROBLEM AREA============		

			Redim Preserve tmp1(0 To x) As String

			

			tmp1(x) = DocTwo.ChecklistTemplate(0)

			

			Set Ventry = vcollection.GetNextEntry(Ventry) 

			x = x+1

			

		Wend

		‘===========END PROBLEM AREA============

		ulist = Unique(tmp1)

		

		Forall u In ulist

			

			reslist = reslist & Chr$(10) & u

			Set ATEview = db.GetView("ActivityByTemplate3")

			

			Set ATEcollection = ATEview.GetAllEntriesByKey(u, True)

			

			Dim ATEentry As NotesViewEntry

			Set ATEentry = ATEcollection.GetFirstEntry()

			

			While Not(ATEentry Is Nothing)

				Set accessdoc = ATEentry.Document

				Call prt_Data(accessdoc, keys)	

				Set ATEentry = ATEcollection.GetNextEntry(ATEentry)

			Wend

			

		End Forall

		

		Call EndHTML	

	End If

	

	'**********************************************************

	'HOW DO I reinitialise my array..I guess will have to be done here!

	

	'**********************************************************

	

	Set viewEntry = viewNav.GetNext ( viewEntry )

	

Wend

Subject: Help with Redim preserve and CLear

Your first question: How do I clear my array such that I do not lose the pointer reference? What do you mean by this? What pointer reference?

Since the array is put on the local stack, its contents is cleared when you leave the function. Maybe you will free some memory when you redim the array back to 0 when you are done with it.

Subject: Help with Redim preserve and CLear

Redim Preserve needs to make a new array and copy the elements of the existing array into the new array, so every time you call it, it needs to do that much more work. There are a couple of work-arounds. One would be to make the array larger than you think it needs to be to begin with, and add an arbitrarily large number of new index slots every time you expand it. That would mean keeping an integer variable around to keep track of the “real” upper bound of the data, but if you are only calling the redim, say, every hundred times you add a data item instead of every single time, you should see a significant performance improvement. Another workaround would be to use a list instead of an array.