Option Compare Statement

See Also28SHHN5                 ExampleKWODAY>Low

Declares the default comparison mode to use when string data is compared.

Syntax

Option CompareBinary | Text}

Remarks

The Option Compare statement is used in the Declarations section of a form or module2JU32VW to specify the string comparison method for that form or module.

String comparisons can be either Binary or Text.

Binary comparisons are case sensitive; so, for example, an "M" doesn't match an "m".  When determining whether a character is less than, equal to, or greater than another character, the program uses the character's relative order of appearance in the ANSI character set5221FB.

Text comparisons are case insensitive; so, for example, an "M" matches an "m".  In addition, the relative order of characters is not the same as it is for Binary.  For Text comparisons, the relative order of characters is determined by the setting of the country code in the international section of your WIN.INI file.

When  a form or module doesn't include an Option Compare statement, the default text comparison method is Binary.


See Also

ANSI Character Set108ABF

Comparison OperatorsNRJZ1K

InStr FunctionPSLW56

StrComp Function4EP49UH


Option Compare Statement Example

The example uses the Option Compare statement to set the string comparison method.  To try this example, paste the code into the Declarations section of a form.  Then press F5 and click the form.

 

Option Compare Text                      ' Set string comparison.

Sub Form_Click ()

  Dim LName, Msg, NameStr, UName         ' Declare variables.

  NameStr = InputBox("Enter your name.") ' Get name from user.

  UName = UCase(NameStr)                 ' Make uppercase version.

  LName = LCase(NameStr)                 ' Make lowercase  version.

  If UName Like LName Then               ' Compare them.

    Msg = "'" & UName & "' matches '" & LName & "'. End the program, "

    Msg = Msg & "then remove the 'Option Compare Text' line from the "

    Msg = Msg & "Declarations section of the form and try the example again."

  Else

    Msg = "Now, '" & UName & "' does not match '" & LName & "'."

  End If

  MsgBox Msg                             ' Display message.

End Sub