VB10 vs VB6: As Any
This is part of series of posts categorized under VB10 vs VB6.
Declare Sub ExternalMethodName Lib "SomeLibrary" (ByVal someValue As Any)
When working with Windows API's, you use the DECLARE statement to define the external method. In VB6, you could use the As Any variable declaration; doing so would allow you to pass any variable type to the external method. It's key to note, when I say any, I mean any. VB6 would not protect you in any way against passing in something that you didn't mean to do so. Sure, this puts the responsiblity on the developer to do the right thing; however, last I checked, I now have 4 cores in my machine that are hyperthreaded providing 8 processing pipelines along with 16GB of memory. I want my development environment to do everything it can to help me write better software. Leaving it up to me to write comments or remember what types can be passed is kind of, well, annoying. Wouldn't it be great if there was some way that you could declare an external method that could support multiple valid appropriate variable types? Oh wait, there is...
Declare Sub ExternalMethodName Lib "SomeLibrary" (ByVal intValue As Integer)
Declare Sub ExternalMethodName Lib "SomeLibrary" (ByVal stringValue As String)
VB10 allows you to use overloaded method signatures. As long as the parameters have a different signature, as defined by the number, order and type of parameters, you can create as many of these as you'd need. By doing this, the IDE and compiler are able to protect you from passing in something you didn't mean to, thus helping you to write better applications. And when using these externally defined methods, the correct one will be automatically utilized based on the variable type that you use.
So although VB10 does not support As Any, I'd say that this is a case where the language has evolved and it's a solid step in the right direction. When moving to VB10, the IDE is really great about pointing out what variable type(s) you might be using and it takes only moments to rid yourself of the troublesome As Any pitfalls utilizing overloaded declares. With that said, I'm going to give this one to VB10.