Testing whether an item is in an array
2685 pts.
0
Q:
Testing whether an item is in an array
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
ASKED: Aug 12 2009  3:23 PM GMT
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
0
2685 pts.
0
A:
 RATE THIS ANSWER
0
Click to Vote:
  •   0
  •  0
  • AddThis Social Bookmark Button
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
Last Answered: Aug 12 2009  4:43 PM GMT by Brooklynegg   2685 pts.
0
0
Discuss This Answer:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _



_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _

Ppolette   275 pts.  |   Aug 14 2009  3:04PM GMT

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

 

Brooklynegg   2685 pts.  |   Aug 14 2009  3:52PM GMT

Thanks for your response. I will work this into my test and production code for this change.

Thanks again.

 
0