Option Compare 语句

模块级别 用于声明在比较字符串数据时使用的默认比较方法。

语法

Option Compare { Binary | Text | Database }

备注

如果使用 Option Compare 语句,则该语句必须在模块中出现在任何过程之前。

Option Compare 语句为模块指定了字符串比较方法(BinaryTextDatabase)。 如果模块不包括 Option Compare 语句,则默认文本比较方法为 Binary

  • Option Compare Binary 根据派生自字符的内部二进制表示形式的排序顺序生成字符串比较。 在 Microsoft Windows 中,排序顺序由代码页决定。 典型二进制排序顺序如以下示例中所示:

    A < B < E < Z < a < b < e < z < À < Ê < Ø < à < ê < ø 
    
    
  • Option Compare Text 会导致基于由您系统的区域设置决定的区分大小写的文本排序顺序的字符串比较。 使用 选项比较文本对相同字符进行排序时,将生成以下文本排序顺序:

      (A=a) < ( À=à) < (B=b) < (E=e) < (Ê=ê) < (Z=z) < (Ø=ø) 
    
    
  • Option Compare Database 只能在 Microsoft Access 中使用。 这将导致基于由执行字符串比较的数据库的区域设置 ID 决定的排序顺序的字符串比较。

示例

此示例使用 Option Compare 语句设置默认字符串比较方法。 Option Compare 语句仅在模块级使用。

' Set the string comparison method to Binary. 
Option Compare Binary ' That is, "AAA" is less than "aaa". 
' Set the string comparison method to Text. 
Option Compare Text ' That is, "AAA" is equal to "aaa". 

另请参阅

支持和反馈

有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。