Using arrays -> "Type Mismatch"

I believe the offending line is:“If (cARR(i) = useroffice) And (nARR(i) = policy) Then”

but I’m not sure

Option Public

Option Explicit

Const nab_server = “Hercules/RDS”

Const nab_path_and_file = “names.nsf”

Const lookup_server = “Athena/RDS”

Const lookup_path_and_file = “newNAS\AdmnTask.nsf”

Const lookup_view = “IT Office”

Const FILE_PATH=“d:\export\IncorrectPolicy_Report_Array.txt”

Sub Initialize

'On Error Resume Next	

Dim this_db As notesdatabase

Dim session As New notessession

Dim NAB As notesdatabase

Dim LU As NotesDatabase

Dim person As NotesDocument

Dim IT_Office As NotesDocument

Dim array_doc As NotesDocument

Dim people_view As notesview

Dim cARR() As String

Dim nARR() As String

Dim i As Integer

Dim lookup_view  As NotesView

Set this_db=session.CurrentDatabase

Dim log_doc As notesdocument



Set LU=session.getdatabase(lookup_server, lookup_path_and_file,False)

Set lookup_view = LU.GetView("IT Office")



i = 0



Redim cARR(0)

Redim nARR(0)



Dim counter As Integer

Dim username As NotesName

Dim userstring As String

Dim useroffice As String

Dim policy As String



Open FILE_PATH For Output As #1

Print #1, "Incorrect Archive Policy Report: " & Cstr(LU.Title) & " Date: " & Today()

Print #1, "Building Certifier to Notes Server mapping array ..."	



Forall view In LU.views

	If view.Name = ("IT Office") Then

		Set array_doc = 	view.GetFirstDocument

		While Not array_doc Is Nothing

			Redim Preserve cARR(i)

			Redim Preserve nARR(i)

			If array_doc.Certifier(0) = "HQ" Then

				cARR(i) = "HHQ"

			Else

				cARR(i) = array_doc.Certifier(0)					

			End If

			If (Instr(array_doc.Notes_Server(0), "/") >0) Then

				nARR(i) = Left(Right(array_doc.Notes_Server(0), 10), 3)

			Else

				nARR(i) = array_doc.Notes_Server(0)

			End If

			

			Print #1, "Certifier: " & cARR(i) & ", Notes Server: " & nARR(i)

			Set array_doc = view.GetNextDocument(array_doc)

			i = i + 1

		Wend

	End If

End Forall





Set NAB=session.getdatabase(nab_server, nab_path_and_file,False)

Dim nab_dc As notesdocumentcollection

Set people_view = NAB.GetView("People")

Set nab_dc=NAB.AllDocuments

Set person = nab_dc.GetFirstDocument



counter=0



While Not (person Is Nothing)		

	counter=0		

	'Criteria which would EXCLUDE document from report

	If (Instr(person.MailAddress(0), "brightmail") >0) Then

		counter = 1

	End If

	If (Instr(person.MailServer(0), "LNSHHQ02M") >0) Then

		counter = 1

	End If

	If (Instr(person.MailServer(0), "LNSHHQ03M") >0) Then

		counter = 1

	End If

	If (Instr(person.MailServer(0), "NotesGate01") >0) Then

		counter = 1

	End If

	

	'Getting the Fullname Office and the Policy Office

	Set username=New notesname(person.fullname(0))		

	'Print #1, "Checking..."+Username.Abbreviated

	useroffice = Strleft(Strrightback(Cstr(person.fullname(0)), "OU="), "/")

	

	If (Instr(person.Policy(0), "/") >0) Then

		policy = Right(person.Policy(0), 3)

	Else

		policy = person.Policy(0)

	End If

	

	If (useroffice = policy) Then

		counter = 1

	End If

	

	Dim certifier As String		

	

	If (person.form(0)="Person") Then

		

		i = 0

		Do While i <= Ubound(cARR)

			If (cARR(i) = useroffice) And (nARR(i) = policy) Then

				counter = 1

				Exit Do

			End If

		Loop

		

	End If

	

	

	userstring = Cstr(person.fullname(0))

	

	If (counter = 0) Then

		Print #1, "*****************************************!!!!!!!"+ " Office = " + useroffice + ", Policy = " + policy

	Else

		Print #1, "Counter=" & Cstr(counter) & ", MailAddress=" & person.MailAddress(0) & ", MailServer=" & person.MailServer(0) & ", UserOffice=" & useroffice & ", Policy=" & policy

	End If

	

	Set person=nab_dc.GetNextDocument(person)

	

	

Wend



	'People who will receive this memo:

Dim recipients(3) As String

recipients(0)="Michael T Chang"



' mail off the memo

Set this_db = session.CurrentDatabase



Dim doc As notesdocument

Set doc = New NotesDocument( this_db )

doc.form="Memo"

doc.subject="Daily Incorrect Policy Report"



Dim rtitem As NotesRichTextItem

Set rtitem = New NotesRichTextItem( doc, "Body" )

Dim object As Variant

Set object = rtitem.EmbedObject( EMBED_ATTACHMENT, "", FILE_PATH)

Call doc.send(False,recipients)

End Sub

any ideas on what I’m doing wrong?

thks,

-MC

Subject: SOLUTION: using arrays → “Type Mismatch”

Not all documents were person docs and so some of the fields being assigned were not applicable.

I placed the If person doc check at the beginning of the person doc applicable code and the program runs fine

hope this helps someone:

Sub Initialize

'On Error Resume Next	

Dim this_db As notesdatabase

Dim session As New notessession

Dim NAB As notesdatabase

Dim LU As NotesDatabase

Dim person As NotesDocument

Dim IT_Office As NotesDocument

Dim array_doc As NotesDocument

Dim people_view As notesview

Dim cARR() As String

Dim nARR() As String

Dim i As Integer

Dim lookup_view  As NotesView

Set this_db=session.CurrentDatabase

Dim log_doc As notesdocument



Set LU=session.getdatabase(lookup_server, lookup_path_and_file,False)

Set lookup_view = LU.GetView("IT Office")



i = 0



Redim cARR(0)

Redim nARR(0)



Dim counter As Integer

Dim username As NotesName

Dim userstring As String

Dim useroffice As String

Dim policy As String



Open FILE_PATH For Output As #1

Print #1, "Incorrect Archive Policy Report: " & Cstr(LU.Title) & " Date: " & Today()

Print #1, "Building Certifier to Notes Server mapping array ..."	



Forall view In LU.views

	If view.Name = ("IT Office") Then

		Set array_doc = 	view.GetFirstDocument

		While Not array_doc Is Nothing

			Redim Preserve cARR(i)

			Redim Preserve nARR(i)

			If array_doc.Certifier(0) = "HQ" Then

				cARR(i) = "HHQ"

			Else

				cARR(i) = array_doc.Certifier(0)					

			End If

			If (Instr(array_doc.Notes_Server(0), "/") >0) Then

				nARR(i) = Left(Right(array_doc.Notes_Server(0), 10), 3)

			Else

				nARR(i) = array_doc.Notes_Server(0)

			End If

			

			Print #1, "Certifier: " & cARR(i) & ", Notes Server: " & nARR(i)

			Set array_doc = view.GetNextDocument(array_doc)

			i = i + 1

		Wend

	End If

End Forall



Set NAB=session.getdatabase(nab_server, nab_path_and_file,False)

Dim nab_dc As notesdocumentcollection

Set people_view = NAB.GetView("People")

Set nab_dc=NAB.AllDocuments

Set person = nab_dc.GetFirstDocument



While Not (person Is Nothing)		

	If (person.form(0)="Person") Then		

		counter=0		

	'Criteria which would EXCLUDE document from report

		If (Instr(person.MailAddress(0), "brightmail") >0) Then

			counter = 1

		End If

		If (Instr(person.MailServer(0), "LNSHHQ02M") >0) Then

			counter = 1

		End If

		If (Instr(person.MailServer(0), "LNSHHQ03M") >0) Then

			counter = 1

		End If

		If (Instr(person.MailServer(0), "NotesGate01") >0) Then

			counter = 1

		End If

		

	'Getting the Fullname Office and the Policy Office

		Set username=New notesname(person.fullname(0))		

	'Print #1, "Checking..."+Username.Abbreviated

		useroffice = Strleft(Strrightback(Cstr(person.fullname(0)), "OU="), "/")

		

		If (Instr(person.Policy(0), "/") >0) Then

			policy = Right(person.Policy(0), 3)

		Else

			policy = person.Policy(0)

		End If

		

		If (useroffice = policy) Then

			counter = 1

		End If

		

		i = 0

		Do While i <= Ubound(cARR)

			If ((cARR(i) = useroffice) And (nARR(i) = policy)) Then

				counter = 1

				Exit Do

			End If

			i = i + 1

		Loop			

		

		userstring = Cstr(person.fullname(0))

		If (counter = 0) Then

			Print #1, "*****************************************!!!!!!!"+ " Office = " + useroffice + ", Policy = " + policy

		Else

			Print #1, "Counter=" & Cstr(counter) & ", MailAddress=" & person.MailAddress(0) & ", MailServer=" & person.MailServer(0) & ", UserOffice=" & useroffice & ", Policy=" & policy

		End If

		

	End If

	

	Set person=nab_dc.GetNextDocument(person)

Wend



	'People who will receive this memo:

Dim recipients(1) As String

recipients(0)="Michael T Chang"



' mail off the memo

Set this_db = session.CurrentDatabase



Dim doc As notesdocument

Set doc = New NotesDocument( this_db )

doc.form="Memo"

doc.subject="Daily Incorrect Policy Report"



Dim rtitem As NotesRichTextItem

Set rtitem = New NotesRichTextItem( doc, "Body" )

Dim object As Variant

Set object = rtitem.EmbedObject( EMBED_ATTACHMENT, "", FILE_PATH)

Call doc.send(False,recipients)

End Sub

Subject: RE: SOLUTION: using arrays → “Type Mismatch”

There are more problems, like the fact that you’ve hard-coded 1 as the file handle. You don’t know (and can’t know) before runtime what file handle is going to be available. Use Freefile to get your file handle.

Subject: using arrays → “Type Mismatch”

What did you do to the simple (and elegant) code I gave you?

Subject: RE: using arrays → “Type Mismatch”

There’s actually no excuse for not knowing the exact line on which your error occurs. It’s quite easy to use the Domino debugger to trace thru your code and see the values of your variables. Here’s a guide to that and other ways of debugging code: part 1 and part 2.

Subject: using arrays: Runs from client, “Type Mismatch” when scheduled on server

Here’s the offending line of code:Forall view In LU.views

This is a scheduled agent. If I and select “Run”, it ties up my workstation for a few minutes but does exactly what it’s supposed to.

When I let it run on schedule (on the server) I get a type mismatch error

any ideas?

thks,

-MC

Subject: RE: using arrays: Runs from client, “Type Mismatch” when scheduled on server

Why the Forall? The only case in which you’re doing anything is when the name is “IT Office”. So why not use the GetView method of the NotesDatabase to get only the view you’re going to use?

Subject: RE: using arrays: Runs from client, “Type Mismatch” when scheduled on server

because I copied the piece of code from somewhere else and couldn’t get the “GetView” method to work

I know, it’s a lame excuse,

-MC

Subject: ok, got it to work

I changed:Forall view In LU.views

If view.Name = (“IT Office”) Then

End If

End Forall

To:

Dim view As NotesView

Set view = LU.GetView( “IT Office” )