9) Which of these statements is syntactically legal? Why?
(a)
(a) is legal. The rest are illegal.
(a) is legal because you can put as many unary positive or negative operators on top of a constant as you want, so long as it's a numeric constant.
Clearly VBScript is inconsistent insofar as how unary operators and constants work together. These inconsistencies are one those unfortunate corner cases that got missed when the parser was designed.
10) Which of these statements is syntactically legal? Why?
(a) is illegal, the rest are legal.
The VBScript single-line
(b) is perfectly legal, nothing odd here.
(a) is legal in VB6 but not in VBScript because of a mistake. The parser sees IF ID THEN ID ELSE... and tries to parse "ID ELSE" as a statement. The statement processor
A number of people pointed out that having both
Class ABC Public Default Sub DEF(X) Msgbox X.Name End Sub Public NameEnd ClassSet Foo = New ABCFoo.Name = "Foo"Set Bar = New ABCBar.Name = "Bar"Blah = TrueIf Blah Then Foo Bar Else Bar Foo
(d) is another mistake. The VB6 parser does not allow this, but VBScript does. As with #8, we couldn't fix it when we found it because it would have broken existing ASP page and web pages. The
Funny story: I actually fixed this one for a beta release of the engines and a certain influential news site was broken by the fix. Bizarrely enough they had a web page with this syntax in it. They said they would give the new version of IE a bad review if upgrading broke even a single one of their hundreds of thousands of pages! Backwards compatibility is very, very important in the scripting world. Of course we rolled the change back, and there's a comment in the code now cautioning future maintenance programmers to never change it.