IsInArray - Check for value in an array

There have been many occassions where I've needed to check for a given value within an array in VBScript. There's no built-in function for this, so I crafted my own.

 

Function IsInArray(strIn, arrCheck)

    'IsInArray: Checks for a value inside an array

    'Author: Justin Doles - www.DigitalDeviation.com

    Dim bFlag bFlag = False

    If IsArray(arrCheck) AND Not IsNull(strIn) Then

        Dim i

        For i = 0 to UBound(arrCheck)

            If LCase(arrcheck(i)) = LCase(strIn) Then

                bFlag = True

                Exit For

            End If

        Next

    End If

    IsInArray = bFlag

End Function

Usage:
If IsInArray(value, array) Then
    WScript.Echo "Yes"
End If

Your rating: None Average: 3.7 (11 votes)