I’m having issues now with an agent of mine…During testing, never had any problems…as soon as I make it live, I’m getting these errors of Subscript out of range.
Basically the part of the script looks to see if a field is filled. If it’s populated, it will then proceed to create a list of users listed in that field…Here is the code:
'check to see if ticket was opened on behalf of
If Me.m_ardoc.RefUser(0) = " " Then…
…
This would send an email to the author of the email
…
Else
'RefUsers Exist…Sending email to Requester, REfUsers, and Tech
'RefUser is checked and tallyed to include all users.
Dim getdata As Variant
Dim n
Dim recipients( 1 To 8 ) As String
getdata = Me.m_ardoc.RefUser
Forall gd In getdata
n = n + 1
recipients(n) = gd
End Forall
It’s this part, the recipents(n) = gd which I’m constantly getting Subscript out of range. Now I’m thinking it’s the beginning when it’s checking to see if the field is blank…It’s not working and it trying to tally a empty field and erroring out.
Thoughts?
Edmound
Subject: Subscript out of Range…
Hi Edmound,
Is it possible that the RefUser field has more than 8 elements in it (in the production document)? Since your recipients array only allows 8 values, it is possible that the code is trying to write 9 elements to it.
You should use a redimmable array, where the redimmable array index is equal to n. Make sure you use the “Preserve” keyword when you redim the array, or previous values entered into the array will be erased.
Thanks,
Joe
Subject: RE: Subscript out of Range…
Sorry I should have mentioned. The refuser is restricted. a user can only populate 5 names, so 8 should be plenty. I’m thinking it’s trying to action it, even if the Refuser field is blank.
I’m seeing the error occur when the RefUser is blank.
Subject: RE: Subscript out of Range…
Hi Edmound,
I can’t think of anything at the moment, but I should caution you that your if-then condition in the following line is looking for a space – not an empty value:
If Me.m_ardoc.RefUser(0) = " " Then… ’ this is looking for a space character – not a blank value
I’ll post again if I can think of anything else.
Thanks,
Joe
Subject: RE: Subscript out of Range…
It’s hasn’t happened again so far today except for first thing this morning…Yesterday it was happening all the time and I thought, well okay maybe since the field was NULL, I put a default space into the field if it’s blank and update the script to look for the space…
I’m going to do a view testers to make sure that everything is working the way it should be…But does the code look alright?
Subject: RE: Subscript out of Range…
The variable “n” is not set to any particular data type. That means it will default to a variant, which Notes should interpret as a number once you increment it. However, I’d give n a datatype of int or long.
The only other thing I can think of is to run the code in the debugger (as Matt suggested), and when the code crashes, let us know the value of n.
Thanks,
Joe
Subject: RE: Subscript out of Range…
Thanks for the replies…The issue seems to have resolved itself!
Subject: debug it
I would debug it, and maybe put a STOP right after setting the getdata variant value.
Possibly some values are being parsed because they have commas in them or something, so instead of 4 items, they are getting 8?
I’m sure we are all curious as to what happens.
Subject: never mind
sorry, I suggested something, then looked at it again. Wish I could delete this.
Subject: You can delete it
At least in the sense of removing the message content and changing the topic to a one-liner like “please ignore” or something.
But sometimes it is even helpful to read a suggestion, that the author later found out to not hit it.
Subject: Subscript out of Range…
Where is the error occuring in the debugger.
Here are the two places I would check / change your code:
You’re assuming this variable exist.
If Me.m_ardoc.RefUser(0) = " " Then…
Maybe it doesn’t add this if before the above
If Me.m_ardoc.HasItem(“RefUser”) Then
If Me.m_ardoc.RefUser(0) = " " Then…
etc.
The other place I would double check:
Dim recipients( 1 To 8 ) As String
getdata = Me.m_ardoc.RefUser
Forall gd In getdata
n = n + 1
if n > 8 then
MsgBox "More than 8"
Exit Sub
End if
recipients(n) = gd
End Forall
Subject: RE: Subscript out of Range…
Thanks for the response…I’ll check and see what happens…So far aside from the one notification this morning I haven’t seen it again, and the agent has processed many documents since then…So maybe it’s resolved itself…