Subscript out of range

Can anyone pinpoint why this code generates the “Subscript out of range” error?

Option Public

Option Explicit

Const nab_server = “Athena/RDS”

Const nab_path_and_file = “names.nsf”

Const lookup_server = “Hercules/RDS”

Const lookup_path_and_file = “newNAS\AdmnTask.nsf”

Const lookup_view = “IT Office”

Const FILE_PATH=“c:\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")



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



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)



Forall view In LU.views

	Print #1, "got past the LU.Views Forall"

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

		Print #1, "Got past the view.Name is IT office"

		Set array_doc = 	view.GetFirstDocument

		While Not array_doc Is Nothing

			Print #1, "Entering the 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)					

				cARR(i) = "test"				

			End If

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

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

			'Else

				'nARR(i) = array_doc.NotesServer(0)

			'	nARR(i) = "NQ?"

			'End If

			

			i = i + 1

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

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

			Set array_doc = view.GetNextDocument

		Wend

	End If

End Forall

End Sub

Subject: Subscript out of range

I wasn’t able to test your code, but looking at it i can guess what could cause the problem. Its the print line after you increment the integer i by 1.

So just intechange these to lines from

i = i + 1

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

to

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

i = i + 1

cheers !!

Ashish

Subject: RE: Subscript out of range

Yes, generally with anything in a ForAll and an increment, the increment should be the last thing you do before you being the loop again. So as suggested, move the increment to after the last print and you’ll be fine

Subject: Subscript out of range … moving the i=i+1 to the end worked

thanks for the help

also I changed the line near the end from:

Set array_doc = view.GetNextDocument

to:

Set array_doc = view.GetNextDocument(array_doc)

and now the script (at least the above section of it) is working

thks,

-MC