Public Function FilterB02(sSourceArray() As String, _
sMatch As String, _
sTargetArray() As String, _
Optional bInclude As Boolean = True, _
Optional lCompare As VbCompareMethod = vbBinaryCompare) As Long
' by Donald, donald@xbeat.net, 20000918
' Modified by Keith, kmatzen@ispchannel.com
' returns Ubound(sTargetArray), or -1 if sTargetArray is not bound (empty array)
Dim lNdx As Long
Dim lLo As Long
Dim lHi As Long
Dim lLenMatch As Long
lLenMatch = Len(sMatch)
lLo = LBound(sSourceArray)
lHi = UBound(sSourceArray)
ReDim sTargetArray(lHi - lLo) 'make maximal space
FilterB02 = -1
If lLenMatch Then
If bInclude Then 'Need a match
For lNdx = lLo To lHi
If Len(sSourceArray(lNdx)) >= lLenMatch Then
If InStr(1, sSourceArray(lNdx), sMatch, lCompare) Then
FilterB02 = FilterB02 + 1
sTargetArray(FilterB02) = sSourceArray(lNdx)
End If
End If
Next
Else 'Need a mismatch
For lNdx = lLo To lHi
Select Case Len(sSourceArray(lNdx))
Case Is < lLenMatch 'Can't match
FilterB02 = FilterB02 + 1
sTargetArray(FilterB02) = sSourceArray(lNdx)
Case Else
If InStr(1, sSourceArray(lNdx), sMatch, lCompare) = 0 Then
FilterB02 = FilterB02 + 1
sTargetArray(FilterB02) = sSourceArray(lNdx)
End If
End Select
Next
End If
ElseIf bInclude Then 'Include all
For lNdx = lLo To lHi
FilterB02 = FilterB02 + 1
sTargetArray(FilterB02) = sSourceArray(lNdx)
Next
End If
' erase or shrink
If FilterB02 = -1 Then
Erase sTargetArray
Else
ReDim Preserve sTargetArray(FilterB02)
End If
End Function
|