Option Compare Statement

Description

Used at module level to declare the default comparison mode to use when string data is compared.

Syntax

Option Compare {Binary | Text}

Remarks

If used, the Option Compare statement must appear in a module before any statements that declare variables or define constants.

The Option Compare statement specifies the string comparison method (Binary or Text) for a module. If a module doesn't include an Option Compare statement, the default text comparison method is Binary.

Option Compare Binary results in string comparisons based on a sort order derived from the internal binary representations of the characters. In Microsoft Windows, sort order is determined by the code page. On the Macintosh, sort order is determined by the character set. In the following example, a typical binary sort order is shown:


A < B < E < Z < a < b < e  < z < À < Ê < Ø < à < ê < ø

Option Compare Text results in string comparisons based on a case-insensitive textual sort order determined by your system's locale. The same characters shown above, when sorted using Option Compare Text, produce the following text sort order:


(A=a) < ( À=à) < (B=b) < (E=e) < (Ê=ê) < (Z=z) < (Ø=ø) 

See Also

Comparison Operators, InStr Function, Option Base Statement, Option Explicit Statement, Option Private Statement, StrComp Function.

Example

This example uses the Option Compare statement to set the default string comparison mode. The Option Compare statement is used at the module-level only.


' Set the string comparison method to Binary.
Option Compare Binary     ' i.e. "AAA" less than "aaa"
' Set the string comparison method to Text.
Option Compare Text    ' i.e. "AAA" equal to "aaa".