bIsInArray Function:
Determine if a Value/Object exists in an any kind multidimensional array.
Description:
This function is very handy for checking whether a Value or Pointer to an Object exists in an any multidimensional array. Ordinarily most programmers will use the LBound/UBound values of an array to loop through the array. Handling the multidimensional arrays is even worse and sometimes really painfull. Here is a very fast way of checking any type of array for some value.
Syntax:
boolean = bIsInArray(ValueToFind, aArray)
Example:
<%
Dim vArr(100, 100), n, m For n = 1 To 100 For m = 1 To 100 vArr(n, m) = Int(Rnd * 100) Next Next '--- Force last element as target; worst case vArr(100, 100) = 500
response.write bIsInArray(500, vArr)
'--- returns: True
%>
ASP Source Code:
<%
Public Function bIsInArray(ByRef FindValue, ByRef vArr) Dim vArrEach For Each vArrEach In vArr If IsObject(FindValue) Then bIsInArray = FindValue Is vArrEach Else bIsInArray = (FindValue = vArrEach) End If If bIsInArray Then Exit For Next End Function
%>
|