Remove duplicates errors/problems

Hello,i am trying to create a script to remove double entries in a folder from lotus. i do not know what is wrong, sometimes the script just stops, sometimes i get the error that the Object varioable not set (or something like that.

I have checked with the debugger, and the error of variable not set comes to dco1 8in the script) which makes no sense, because the loop should exit when doc1 is nothing.

when running the script in debugger and checking variable values, i see very strange things happening, namely with doc1 values, sometimes , after a document has been deleted, it does not get the next value (when saying getnext) but the last value of the whole list of documents, which makes no sense (to me and a colleague that looked with me)

Can anybody help

here is the script, i use a lot of variables because i have seen in the forums that using a getnext with the same variable can cause errors

Dim session As New NotesSession

Dim db As notesdatabase

Dim allhtml As NotesView

Dim doc1 As notesdocument

Dim doc2 As notesdocument

Dim doc3 As notesdocument

Dim doc4 As notesdocument

Dim doc5 As notesdocument

Dim doc6 As notesdocument

Dim messago As String

Dim messag2 As String



Set db =session.currentdatabase

Set allhtml = db.getview("HTMLPDFSent")

Set doc1=allhtml.getlastdocument

Set doc4 = doc1



Do While Not (doc1 Is Nothing)

	Set doc4 = doc1

	

	Set doc2 = allhtml.getprevdocument (doc1)

	

	Do While Not (doc2 Is Nothing)

	'	Messagebox doc2.Subject (0), MB_OK, "doc2"

		Set doc6 = doc2

		

		If Trim(Ucase(doc1.Subject(0))) = Trim(Ucase(doc2.Subject(0))) Then

			Set doc3 = doc2

			Set doc2 = allhtml.getprevdocument (doc6)

			doc3.remove True

		Else

			Set doc2 = allhtml.getprevdocument (doc6)

			

		End If

	Loop		

	Set doc5 = allhtml.getprevdocument (doc4)

	Set doc1 = doc5

	Messagebox doc1.Subject (0), MB_OK, "doc1"

Loop

thanks for any help…

Subject: Remove duplicates errors/problems

Can you write your script in pseudo-code so we know what you are trying to do exactly?

Subject: RE: Remove duplicates errors/problems

Hi Yanick,

i am not sure what pseudo code is, but here is what i am trying to do

look into folder HTMLPDF

take first document (last one that arrived, most recent) (doc1)

do while there are documents in the folder

get next document(doc2)

compare subjects (doc 1 vs doc2)

if they are the same, delete older document(delete doc2)

loop (until doc2 is empty, end of documents)

get next document for doc1 and repeat above for all documents in the folder, until doc1 is empty

basically i am trying to remove duplicates from a folder called HTMLPDF.

so i take the most recent document, compare it with all the following documents and delete any older ones if there are any (with the same subject)

then i repeat this action until i have gone through all the documents in the view.

i thought about having an easier agent run whenever a new document arrives, starting from an empty folder, but i have seen that ‘after new mail arrives’ option does not work like it should, it does not do what it should do right after, but it actually only happens every 5 minutes and then sometimes takes many documents at the same time if they came within that time frame.

What is really strange is that the script works when i follow it in debugger (variables have correct values), but then all of a sudden the doc1 variable is empty, or takes the last value of the list, for no reason since it has not reached the end of the documents of the folder (something wrong with the getnext option?)

i know i could do this script using only doc1 and doc2 but i saw somewhere that this might cause problems, hence the use of all the other variables.

maybe this simpler version of the code is easier to understand

Sub Initialize

Dim session As New NotesSession

Dim db As notesdatabase

Dim allhtml As NotesView

Dim doc1 As notesdocument

Dim doc2 As notesdocument

Dim doc3 As notesdocument

Set db =session.currentdatabase

Set allhtml = db.getview("HTMLPDF")



Set doc1=allhtml.getlastdocument

messago = doc1.Subject (0) 

time1 = doc1.Created

Set doc4 = doc1



allhtml.Autoupdate = True

Do While Not (doc1 Is Nothing)

	

	Set doc2 = allhtml.getprevdocument (doc1)

	

	Do While Not (doc2 Is Nothing)

		If Trim(Ucase(doc1.Subject(0))) = Trim(Ucase(doc2.Subject(0))) Then

			Set doc3= doc2

			Set doc2 = allhtml.getprevdocument (doc2)

			

			doc3.remove True

			

		Else

			Set doc2 = allhtml.getprevdocument (doc2)

			

		End If

	Loop

	

	Set doc1 = allhtml.getprevdocument (doc1)

	

Loop

End Sub

thanks for the help

Subject: RE: Remove duplicates errors/problems

Hi Thierry,

Try this,

http://www-10.lotus.com/ldd/nd6forum.nsf/DateAllFlatweb/b8bf4454504926f1852572c700408074?OpenDocument