The explanation can be found in this note found buried pretty deeply in the VB 6 documentation:
You are not required to use the Call keyword when calling a procedure. However, if you use the Call keyword to call a procedure that requires arguments, argumentlist must be enclosed in parentheses. If you omit the Call keyword, you also must omit the parentheses around argumentlist. If you use either Call syntax to call any intrinsic or user-defined function, the function's return value is discarded. Emphasis added.
The actual behavior of the code doesn't seem to quite follow the documentation. But one thing is clear, the result is discarded. Not knowing this interesting bit of non-obvious behavior could result in a hard to find bug in VB 6.
Because VB 6 didn't follow the conventions used by other languages and was generally confusing and inconsistent, Microsoft decided to scrap most of the procedure call syntax in VB 6 when they moved to VB.NET. In VB.NET, there is one way to do things and if you don't do it that way, an error results. Let's see what has to be done to convert this code to VB.NET.
One way to convert the VB 6 project is to use the Upgrade Wizard. Just open the VB 6 project in VB.NET and the wizard takes over. But the Upgrade Wizard often misses a lot of optimization and can't convert some things at all. So a lot of programmers just copy and paste the code from VB 6 to VB.NET and correct the errors that result. If you do this with the first code example at the top of the article, there's just one error to correct: the fact that the variable CallingArg isn't declared. When this is declared as String, the program runs! But it doesn't quite get the right result as shown below:
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment