Fabulous Adventures In Coding
Eric Lippert is a principal developer on the C# compiler team. Learn more about Eric.
5) Which of the following statements are guaranteed to never print
(c), as far as I know, always prints
Dim abcabc = 1Class Foo Public Default Property Get Blah Blah = abc abc = abc + 1 End PropertyEnd ClassSet x = new Foo
I can't think of any way that (c) can go into the
Const x = FalseOn Error Resume Nextx = True : If X Then Print True Else Print False
A number of readers pointed out other bizarre ways that (d) can produce False:
Function X : X = False : End FunctionOn Error Resume Nextx = True : If X Then Print True Else Print False
An answer I expected but did not get was the case where X is an object that has a default property, so the assignment is to the default property, not the object. That's not a valid case in VBScript, though it is in VB6. In VB6 the type system can detect when the "Set" is missing because in the VB6 type system, you can declare X as Object. In VBScript everything is Variant, so that trick doesn't work.