See Also Example
Declares the default comparison mode to use when string data is compared.
Syntax
Option Compare { Binary | Text}
Remarks
The Option Compare statement is used in the Declarations section of a 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 set .
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.
ANSI Character Set
Comparison Operators
InStr Function
StrComp Function
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