Visual Basic 6 function "in_array"

Go back

Below you'll find the source for the Visual Basic 6 function in_array.

Attribute VB_Name = "modInArray"
' This function is downloaded from:
' You may freely distribute this file but please leave all comments, including this one, in it.
' @Author Stefan Thoolen <>

Option Explicit

' Searches if a value exists in an array
' Same syntax as the PHP function 'in_array'
' See also:
' I only didn't copy the strict (Boolean) parameter, because we only search in
' strings and not other types.
' @param    String  needle      The string we need
' @param    Variant haystack    The array to look in
' @return   Boolean             True if the value exists, false otherwise
' @author   Stefan Thoolen <>
Public Function in_array(needle As String, haystack() As Variant) As Boolean
    Dim i As Integer, ret As Boolean
    ret = False
    For i = LBound(haystack) To UBound(haystack)
        If haystack(i) = needle Then ret = True
    Next i
    in_array = ret
End Function