Option Compare Statement

Syntax

Option Compare {Binary | Text | Database}

Description

Sets the default method for comparing string data.

Rules at a Glance

  • When Option Compare isn't used in a module, the default comparison method is binary.

  • When Option Compare is used, it must appear at the start of the module's declarations section, before any procedures.

  • Binary comparison—the default text comparison method in Visual Basic—uses the internal binary code of each character to determine the sort order of the characters. For example "A" < "a".

  • Text comparison uses the locale settings of the current system to determine the sort order of the characters. Text comparison is case insensitive. For example "A" = "a".

  • Database comparison is only for use in Microsoft Access. Strings are compared based on the sort order defined by the international settings stored in the database engine.

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.