Posted By

lolrenx on 04/24/13


Tagged


Versions (?)

is in array(str)


 / Published in: Visual Basic
 

check if string is in array (1D only) 1 : boolean 2 : index

  1. Function IsInArray(stringToBeFound As String, arr As Variant) As Boolean
  2. IsInArray = (UBound(Filter(arr, stringToBeFound)) > -1)
  3. End Function
  4.  
  5.  
  6. Function IsInArray(stringToBeFound As String, arr As Variant) As Long
  7. Dim i As Long
  8. ' default return value if value not found in array
  9. IsInArray = -1
  10.  
  11. For i = LBound(arr) To UBound(arr)
  12. If StrComp(stringToBeFound, arr(i), vbTextCompare) = 0 Then
  13. IsInArray = i
  14. Exit For
  15. End If
  16. Next i
  17. End Function

Report this snippet  

You need to login to post a comment.