Skip to content

Instantly share code, notes, and snippets.

@sholsinger
Created April 26, 2011 20:52
Show Gist options
  • Save sholsinger/943116 to your computer and use it in GitHub Desktop.
Save sholsinger/943116 to your computer and use it in GitHub Desktop.
VBScript tool for checking if a value is in an array.
' returns the index of obj in array. obj can be anything. Returns -1 if not found.
Function inArray(arr, obj)
On Error Resume Next
Dim x: x = -1
If isArray(arr) Then
For i = 0 To UBound(arr)
If arr(i) = obj Then
x = i
Exit For
End If
Next
End If
Err.Clear()
inArray = x
End Function
@melaku-z
Copy link

Function inArray(arr, obj)
    inArray = False
    For Each value in arr
        If value = obj Then
            inArray = True
            Exit For
        End If
    Next
End Function

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment