Article ID: 190272
Article Last Modified on 3/3/2005
Sub main()
Dim v1
Dim v2
v1 = "100" ' variant string
v2 = 1000 ' variant integer
msgbox (v1 > v2) ' string variant always > numeric variant
msgbox (v1 > CLng(v2)) ' Clng(v2) is hardtype so it is converted
' to string variant
End Sub
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.
Keywords: kbscript kbprb KB190272