The information in this article applies to:
SYMPTOMSVBScript has a semantic compatibility difference with Visual Basic for Applications (VBA) with regard to hardtype comparisons. Basically, VBA's comparison semantics are such that non-variant values are "hardtypes," meaning that they cannot change types. During comparison, variants must be coerced to their types. The problem is that in VBScript everything is a variant, and VBScript doesn't remember that it's a "hardtype" value. STATUSThis behavior is by design. MORE INFORMATIONSteps to Reproduce BehaviorUse the following code to reproduce this behavior:
If you run this test in VBA, the first comparison (v1 > v2) is True because
variant strings are always greater than variant numbers. In the second
comparison (v1 > CLng(v2)), the CLng() function returns a hardtype long
value; in this case, VBA converts the string variant to the hardtype (long)
and performs the comparison, which returns False. Both comparisons return True in VBScript.
This problem will be apparent for every runtime function that returns a variant in VBScript but returns a hardtype/integral in VBA. This includes the numeric conversions (such as CLng), the math functions (which return double in VBA), and so forth. Additional query words:
Keywords : kbScript kbVBScript kbIE500 |
Last Reviewed: July 13, 1999 © 2000 Microsoft Corporation. All rights reserved. Terms of Use. |