I come from an Object Oriented background. Why does “Test” (notice the quotes) display (in the message box) in this code fragment. I would expect the logical test: ‘If Test = “True”‘ to return False because the variant contains a Boolean and not a String. Therefore I would not expect the Message Box to appear, but it does:
Dim Test As Variant
Test = True
If Test = "True" Then //line 5
MsgBox ("Test")
End If
Varianttype values in VB6 (and most other languages that support them) automatically convert between data types as needed; they’re used extensively in COM interactions.The code you’re using uses the automatic (implicit) conversion from boolean to string here:
after using it as it’s original assigned type (boolean) here
Here, though, you’re not using the variant at all; you’re using a hard-coded string
"Test".