选项比较二进制文本数据库

选项比较二进制

二进制比较使得对模块/类内的字符串相等性的所有检查都区分大小写。从技术上讲,使用此选项,使用每个字符的二进制表示的排序顺序执行字符串比较。

A <B <E <Z <a <b <e <z

如果模块中未指定选项比较,则默认使用二进制。

Option Compare Binary

Sub CompareBinary()

    Dim foo As String
    Dim bar As String
    
    '// Case sensitive
    foo = "abc"
    bar = "ABC"
    
    Debug.Print (foo = bar) '// Prints "False"
    
    '// Still differentiates accented characters
    foo = "ábc"
    bar = "abc"
    
    Debug.Print (foo = bar) '// Prints "False"
    
    '// "b" (Chr 98) is greater than "a" (Chr 97)
    foo = "a"
    bar = "b"
    
    Debug.Print (bar > foo) '// Prints "True"
    
    '// "b" (Chr 98) is NOT greater than "á" (Chr 225)
    foo = "á"
    bar = "b"
    
    Debug.Print (bar > foo) '// Prints "False"

End Sub

选项比较文本

选项比较文本使模块/类中的所有字符串比较使用不区分大小写的比较。

(A | a)<(B | b)<(Z | z)

Option Compare Text

Sub CompareText()

    Dim foo As String
    Dim bar As String
    
    '// Case insensitivity
    foo = "abc"
    bar = "ABC"
    
    Debug.Print (foo = bar) '// Prints "True"
    
    '// Still differentiates accented characters
    foo = "ábc"
    bar = "abc"
    
    Debug.Print (foo = bar) '// Prints "False"
    
    '// "b" still comes after "a" or "á"
    foo = "á"
    bar = "b"
    
    Debug.Print (bar > foo) '// Prints "True"

End Sub

选项比较数据库

选项比较数据库仅在 MS Access 中可用。它将模块/类设置为使用当前数据库设置来确定是使用文本还是二进制模式。

注意:不建议使用此设置,除非该模块用于编写自定义 Access UDF(用户定义的函数),它应该以与该数据库中的 SQL 查询相同的方式处理文本比较。