Filter Function (VB6)

Named Arguments

No

Syntax

Filter(SourceArray, FilterString[, Switch[, Compare]])

SourceArray

Use: Required

Data Type: String or Variant

An array containing values to be filtered.

FilterString

Use: Required

Data Type: String

The string of characters to find in the source array.

Switch

Use: Optional

Data Type: Boolean

A Boolean (True or False) value. If True, the default value, Filter includes all matching values in result; if False, Filter excludes all matching values (or, to put it another way, includes all nonmatching values).

Compare

Use: Optional

Type: Constant of vbCompareMethod Enumeration

An optional constant (possible values are vbBinaryCompare, vbTextCompare, vbDatabaseCompare) that indicates the type of string comparison to use. The default value is 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 is True.

  • The default Compare value is 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.

  • The returned array is always base 0, regardless of any Option Base setting. ...

Get VB & VBA in a Nutshell: The Language 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.