November 9th, 2011

Putting back functionality left out of VB Core – ( If you can't live without Mid when writing WP7 apps ;-) )

For development of windows phone applications a new feature was added to the Visual Basic compiler known as VB Core. This is a reduced version of the runtime designed to allow development for a broader variety of platforms without incurring the larger penalty of having a full VB runtime containing non-supported or older VB6 legacy functionality which are now implemented as part of the framework itself. However this results in some features not being supported on this platform such as Late binding, My functionality and some
legacy VB functions. You may not be targeting WP7 yet but this reduced runtime is also being incorporated into other target platforms such as Portable Class Libraries

For many developers who have been using only VB.Net this may not be an issue as they would be familiar with the .NET framework functionality which is typically what is shown in samples and example code that is translated from C#. WP7 is a new platform and much of the code written for this platform is new as well. However, if you have some legacy code that you want to use on this platform and that code uses some of functionality not supported by VB Core, it is possible to create your own implementations to reinstate this functionality

(DISCLAIMER:
This would be your own implementation of this functionality and you assume all risk and responsibility for maintaining it and any consequent increase in assembly size. Microsoft assumes no responsibility for the quality or accuracy of your implementation. Use this technique at your own risk).

Remember, some of this functionality was left out because it may not be applicable to the platform. An example of this is the My.Computer.FileSystem functionality because the platform utilizes a different form of storage known as Isolated Storage. But there is no reason you couldn’t create your own implementation of My helper functions.

We have created a simple example showing how to reinstate some of the functionality which is not included in VB Core. Examples include Left, Right and Mid functionality.

How do you find the code to create your own implementations of these functions?
The source for the VB Runtime is and other assemblies are publically available, so you can see how these functions are implemented.

http://blogs.msdn.com/b/rscc/archive/2010/08/16/net-framework-4-reference-source-is-available.aspx

You can then choose to either include this code directly in your application or create a simple class library which you can then reference from your projects to ensure that you can use the specific functions you require that are not included in VB Core.  You may want to clean up the implementation a little as there is some throwback code related to VB6 which may no longer be applicable.

The project is designed to show you have to add back missing functionality – if you really can’t life without functions such as Left, Mid, Right.    The sample is designed to show you how you can put back small bits for VB runtime functionality left out of VB if you absolutely need to,  but the recommended course of action would be to use existing framework functionality when targeting these new platforms using the VBCore functionality.

Spotty

VBCoreDemo.zip

Category
Visual Basic

Author

0 comments