Signature (Visual Basic / VBA)
Public Function CompareLikeDataType( _
ByVal vOne As Variant _
, ByVal vTwo As Variant _
, Optional ByVal vCompare As Variant _
) As Integer
Code Examples
CompareLikeDataType("ALL", "all", vbBinaryCompare) = -1
CompareLikeDataType("all", "ALL", vbBinaryCompare) = 1
CompareLikeDataType("ALL", "all", vbTextCompare) = 0
CompareLikeDataType("3", 3) = 1
CompareLikeDataType(Null, 3) = -1
-1 if vOne < vTwo
0 if vOne = vTwo
1 if vOne > vTwo
vTwo
E N D S
vOne E 0 - - -
N + 0 - -
D + + n -
S + + + s
E = Empty
N = Null
D = Date/Numeric
S = String
0 = Return 0
- = Return -1
+ = Return 1
s = Do String comparison with StrComp
n = Do numeric/Date comparison
Parameters
| Parameter | Description |
|---|---|
| vOne | First of two values which are to be compared to determine if it is less than, equal to, or greater than the other. |
| vTwo | Second of two values which are to be compared to determine if it is less than, equal to, or greater than the other. |
| vCompare | Specifies the comparison type and sort order/collating sequence used when comparing string values. vCompare defaults to Binary comparisons if it is missing or Null or cannot be fixed up to a number. |
Notes & Version History
| Function returns | See the following table which describes how comparisons are made depending upon data type of arguments. Similar to the CompareCoerceDataType function, except that one fixes-up numeric values to strings if the other argument is a string. |
| Summary | Empty is less than Null is less than Number is less than String. With Number/Date and Number/Date, use numeric comparison. With Number/Date and String, COMPARE THE VARTYPE. With String and String, use string comparison. |