Subscript out of range error in Lotus Script ---Please help

Hi All,

I am getting this error when i click the Reject button “Subscript out of range”

Here is the code

Set userlist1 = newdoc.GetFirstItem(“claimRejectedList”)

Set approvelist1 = Newdoc.GetFirstItem("claimapprovallist")

userlist = newdoc.claimRejectedList

approvelist = newdoc.claimApprovalList

Set newuserlist = newdoc.GetFirstItem("claimApprovers")



If approvelist1.contains(user) Then

			

			For j=0 To Ubound(approvelist)

				

				If approvelist(j) = user Then

					approvelist(j) = ""

					approvelist = Fulltrim(approvelist)

					

					newdoc.claimApprovalList = approvelist

					

				End If

			Next

When I run it in the debug mode —initially I have more values in approvelist say 6, When I enter my if condition , my array value after fulltrim , gets to 5 and then I get the Subscript out of range

Please help

Thanks in advance,

ac ac

Subject: Subscript out of range error in Lotus Script —Please help

When you find the value you want (and replace and trim the array) use Exit For to get out of the loop.

Subject: RE: Subscript out of range error in Lotus Script —Please help

The limit condition of a For statement is only evaluated once, when you first enter the loop. The For will not notice that Ubound(approvelist) changed since that time.

Why are you doing the trim and field assignment inside the loop anyway?

Subject: Subscript out of range error in Lotus Script —Please help

Hi, I don’t undersatnd the purpose of code, however, might be using a while loop helps here. Something like…

userlist1 = newdoc.GetFirstItem(“claimRejectedList”)

Set approvelist1 = Newdoc.GetFirstItem(“claimapprovallist”)

userlist = newdoc.claimRejectedList

approvelist = newdoc.claimApprovalList

Set newuserlist = newdoc.GetFirstItem(“claimApprovers”)

If approvelist1.contains(user) Then

j=0

ub=Ubound(approvelist)

Do While j<=ub

If approvelist(j) = user Then

approvelist(j) = “”

approvelist = Fulltrim(approvelist)

newdoc.claimApprovalList = approvelist

ub=Ubound(approvelist)

End If

Loop

End IF

Subject: RE: Subscript out of range error in Lotus Script —Please help

Thanks Trapti, the code worked.

Thanks for all U’r help,

Regards,

ac ac

Subject: Subscript out of range error in Lotus Script —Please help

you’ve answered your own question. If your original list has 1 more value in the array than after you do your fulltrim, the ubound is 1 higher than it should be. In your example, ubound is set to six so it’s looking to process a 6th value in the array but now the array has only 5 values and there is no 6th value, error is justified.