Testing whether an item is in an array

3845 pts.
Tags:
Lotus Notes
Lotus Notes 6.x
Lotus Notes Arrays
I am trying to use arraygetindex to test whether a value is in an array. If the value is in the array, the index number of its location is returned. In that case, I want to avoid re-adding the item to the array. If it is not in the array, a NULL value is returned to the variant. In that case, I want to add the value as an item in the array (arrayappend). I can't seem to trap the null condition and take the appropriate action.

1] If I test for "vartestItem is null", I get a Type Mismatch at compile time.

2] If I test for "vartestItem = Null" and the value is in the array, it can tell that the variant contains a number and correctly avoids appending the item.

3] If I again test for "vartestItem = Null" and the value is not in the array, the If statement still goes to the Else condition and acts as if the value is in the arrary, even though I can see in the debugger that the Variant contains Null.

Does anyone know how to properly test whether a value is in an array and append if it is not? I have tried converting the variant to string, expecting a "" value if the value is not in the array, but then I get an Invalid Use Of Null error at run time. It looks like I can trap for Error No. 94, but there must be a better way. Can anyone show me the light?



Software/Hardware used:
Windows

Answer Wiki

Thanks. We'll let you know when a new response is added.

I did more work on this. I found that testing the returned variant with “isnumeric” does the trick without throwing a compile time or run time error.

This is the code from the test button. doc.List is a multi-value field on the form this test button is on. doc.match is a field on the test form that the test button checks against for a match.

I can now go on with my little coding project.

Sub Click(Source As Button)
Dim workspace As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim doc As NotesDocument
Dim vartestItem As Variant
Set uidoc = workspace.CurrentDocument
Set doc = uidoc.Document

varList = doc.List
vartestItem = Arraygetindex( varList , doc.Match(0) )
If Isnumeric(vartestItem) Then
Stop
‘ found; don’t insert
Else
Stop
‘not found; insert
End If

End Sub

Discuss This Question: 2  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • Ppolette
    To test if a var is an array, you can use the function IsArray To test if a var is the null value, you have the function isnull. So your code could be if isnull(arraygetindex(varList , doc.Match(0) )) then .... end if
    435 pointsBadges:
    report
  • Brooklynegg
    Thanks for your response. I will work this into my test and production code for this change. Thanks again.
    3,845 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following