Name
Filter Function
Syntax
Filter(SourceArray
,FilterString
[,Switch
[,Compare
]])
-
SourceArray
Use: Required
Data Subtype: String or numeric
An array containing values to be filtered.
-
FilterString
Use: Required
Data Subtype: String or numeric
The string of characters to find in the source array.
-
Switch
Use: Optional
Data Subtype: Boolean
A Boolean (
True
orFalse
) value. IfTrue
, the default value,Filter
includes all matching values inresult
; ifFalse
,Filter
excludes all matching values (or, to put it another way, includes all nonmatching values).-
Compare
Use: Optional
Data Subtype: Long
An optional constant (possible values are 0,
vbBinaryCompare
; 1,vbTextCompare
) that indicates the type of string comparison to use. The default value is 0,vbBinaryCompare
.
Return Value
A String array of the elements filtered from
SourceArray
.
Description
Produces an array of matching values from an array of source values that either match or don’t match a given filter string. In other words, individual elements are copied from a source array to a target array if they either match or don’t match a filter string.
Rules at a Glance
The default
Switch
value isTrue
.The default
Compare
value is 0,vbBinaryCompare
.vbBinaryCompare
is case-sensitive; that is,Filter
matches both character and case. In contrast,vbTextCompare
is case-insensitive, matching only character regardless of case.
Programming Tips & Gotchas
SourceArray
elements that areEmpty
or that contain zero-length strings (“”) are ignored by theFilter ...
Get VBScript in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.