Filter Function
Main Menu
Description
Returns a zero-based array containing subset of a string array based on a specified filter criteria.

Syntax

Filter( InputStrings, Value[, Include[, Compare]])

The Filter function syntax has these parts:

Part Description
InputStrings Required. One-dimensional array of strings to be searched.
Value Required. String to search for.
Include Optional. Boolean value indicating whether to return substrings that include or exclude Value. If Include is True, Filter returns the subset of the array that contains Value as a substring. If Include is False, Filter returns the subset of the array that does not contain Value as a substring.
Compare Optional. Numeric value indicating the kind of string comparison to use. See Settings section for values.

Settings
The Compare argument can have the following values:

Constant Value Description
vbBinaryCompare 0 Perform a binary comparison.
vbTextCompare 1 Perform a textual comparison.
vbDatabaseCompare 2 Perform a comparison based on information contained in the database where the comparison is to be performed.

Remarks
If no matches of Value are found within InputStrings, Filter returns an empty array. An error occurs if InputStrings is Null or is not a one-dimensional array.
The array returned by the Filter function contains only enough elements to contain the number of matched items.

The following example uses the Filter function appiled to an array of names:

Dim Names, Data
Names = array("James","Julie", "Fred","Jason", "Kieran","Alfie")
Data = Filter(Names, "Ja")
' Data(0) contains "James" and Data(1) would contains "Jason".

In this situation the Filter function would react on the "Ja" in the beginning of the names of "James" and "Jason" in the array of Names.

Data = Filter(Names, "ie") ' Data(0) contains "Julie" contains, Data(1) contains "Kieran" and Data(2) contains "Alfie".

The filter reacts to the "ie" in the end of"Julie" and "Alfie", and also reacts to the "ie" within the name "Kieran" as the filter is not dependent upon possession, but only in content when filtering.

Data = Filter(Names, "F") ' Data(0) contains "Fred".

In this circumstance the filter does react as a case sensitive, so even though there is an "f" to be found in the name "Alfie" the filter well not return "Alfie" as the case does not match.

related to
Replace


Main Menu